Skip to content

Instantly share code, notes, and snippets.

View songpon's full-sized avatar

Songpon Phusing songpon

View GitHub Profile
import hashlib
def check_sum(data):
# if type dict need to cast to string
if type(data)==type({}):
data = str(data)
# lib require to encode to unicode before hash
hash_object = hashlib.md5(data.encode())
return hash_object.hexdigest()
#!/bin/bash
psql mypgdb -c "SELECT d.datname AS Name, pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
ELSE 'No Access'
END AS SIZE
FROM pg_catalog.pg_database d
where d.datname='mypgdb'
ORDER BY
#!/bin/bash
cd /var/log/postgresql; tail -n 500000 postgresql-9.1-main.log > res2 ;grep -A 5 -ir deadlock res2
# java 7 only [https://drive.google.com/file/d/1yNCrwEajgpFnRiIUaB8GW04RCtRDI9Lp/view?usp=sharing]
# ireport [https://drive.google.com/a/itblabla.com/file/d/1XM5_34PxcnpIxuxkOB5Yy3llAOsjE0HE/view?usp=sharing]
./ireport --jdkhome /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
@songpon
songpon / check_postgres_table_size.sql
Last active December 8, 2017 00:41
check postgresql table size , top 20 tables
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20;
# https://stackoverflow.com/questions/37771434/mac-pip-install-pymssql-error
# install freetds
brew unlink freetds;
brew install [email protected];
brew link --force [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
pip install pymssql
CREATE USER readonlyuser WITH ENCRYPTED PASSWORD 'secret';
GRANT USAGE ON SCHEMA public to readonlyuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonlyuser;
-- repeat code below for each database:
GRANT CONNECT ON DATABASE mydbname to readonlyuser;
\c mydbname
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonlyuser; --- this grants privileges on new tables generated in new database "foo"
MASTER_IP=
SLAVE_IP=
# service postgresql stop
su - postgres
psql -c "CREATE ROLE replica WITH PASSWORD 'myreplpassword' LOGIN REPLICATION;"
#Security for master allow standby access
echo "host replication replica $SLAVE_IP/32 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
# set up locale for terminal prevent unknow locale
echo export LC_CTYPE=en_US.UTF-8 >> .profile
echo export LC_ALL=en_US.UTF-8 >> .profile
source ~/.profile
wget https://salsa.debian.org/postgresql/postgresql-common/raw/master/pgdg/apt.postgresql.org.sh
bash apt.postgresql.org.sh
## OpenERP backend ##
upstream openerp {
server 127.0.0.1:8080;
}
server {
listen 443 default;
server_name e-system.afrims.org;
client_max_body_size 2G;