Author Archives: ronaldpringadi

Show postgres lock

https://wiki.postgresql.org/wiki/Lock_Monitoring SELECT blocked_locks.pid AS blocked_pid, blocked_activity.usename AS blocked_user, blocking_locks.pid AS blocking_pid, blocking_activity.usename AS blocking_user, blocked_activity.query AS blocked_statement, blocking_activity.query AS current_statement_in_blocking_process FROM pg_catalog.pg_locks blocked_locks JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid JOIN pg_catalog.pg_locks blocking_locks ON blocking_locks.locktype = blocked_locks.locktype AND blocking_locks.DATABASE IS … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Check all table size in Postgres

The “tables ” is in information_schema The “pg_class” is in System Catalogs 1234567SELECT ist.table_name, reltuples AS "entries", pg_size_pretty(relpages::BIGINT*8*1024) AS SIZE FROM information_schema.tables ist INNER JOIN pg_class c ON (ist.table_name = c.relname) WHERE ist.table_catalog=’ip2_sync_master’ AND ist.table_schema=’public’ ORDER BY relpages DESC, ist.table_name … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Synchronize a postgres table through bash and csv

Please note that the csv export process does not escape commas. 1234567891011121314151617181920212223242526272829303132333435#!/bin/bash DIR=’/root/sql_dump’ mkdir -p "$DIR" cd "$DIR" SIZE=100000 #START=611244350 START=0 END=$((START + SIZE)) STOP=189097000 TABLNAME="schema.tablename" while [[ $START -lt $STOP ]] && [[ $END -le $STOP ]]; do   … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Export and Import Postgres query to CSV

# =========================================================== # Export to CSV # =========================================================== # export PGPASSWORD=”YOURPASSWORD” # psql -U YOURUSERNAME -h YOURHOSTNAME -d YOURDBNAME-t -A -F”,” -c “select * from YOURTABLENAME limit 2″ > output.csv # =========================================================== # Import # =========================================================== # export PGPASSWORD=”YOURPASSWORD” # … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Assorted postgres queries

Get table sizes: SELECT relname AS objectname, relkind AS objecttype, reltuples AS “#entries”, pg_size_pretty(relpages::bigint*8*1024) AS size FROM pg_class WHERE relpages >= 8 ORDER BY relpages DESC;

Posted in Uncategorized | Leave a comment

VirtualBox – Imporving usability on guest OS

GUEST OS: Centos 6.7 final HOST OS: Windows 7 Virtualbox version: 5.0.4 1yum install gcc kernel-devel kernel-headers dkms make bzip2 perl

Posted in Uncategorized | Leave a comment

RedHat or CentOS 6 iptables adding an open port

iptables –line -vnL iptables -I INPUT 5 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT service iptables save

Posted in Uncategorized | Leave a comment

Postgres SSD optimization

If you’re running your database on an SSD instead of a spinning disk, you might want to optimize postgres table space cost: 12345678910– Change the tablespace cost ALTER TABLESPACE pg_default SET ( seq_page_cost = 20,  random_page_cost = 1 ); — … Continue reading

Posted in Database, PostgreSQL | Leave a comment

Ant Junit debugging

Sometime we want to debug why ant build failed when executing a certain JUnit Make sure your ant junit task look like the following 1234<junit printsummary="withOutAndErr" haltonfailure="yes"> : : </junit> and not like 1234<junit printsummary="yes" haltonfailure="yes"> : : </junit>

Posted in Uncategorized | Leave a comment

Delete Postgres Cache

1234#!/bin/bash sync echo 1 > /proc/sys/vm/drop_caches service postgresql-9.3 restart

Posted in Database, PostgreSQL | Leave a comment