Monthly Archives: June 2016

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