PostgreSQL - Dump Restore

Dump database:

pg_dump db > dump.sql

Dump all DBs and compress in GZIP with nice:

su postgres -c /usr/bin/pg_dumpall | nice -n15 gzip -c --fast > /var/backups/dumpall.sql.gz

Dump server and restore on server2 at the same time:

pg_dump -C -h server -U user db | psql server2 -U user db

Dump DB from server to local file:

pg_dump -C -h server -U username db > /root/dump.sql

Dump single table from db and restore on database db2:

pg_dump -t table db | psql db2

Dump single table:

pg_dump db -t table > /root/dump.sql

Restore dump from file:

psql -h server -U user db < dump.sql

Restore single table:

psql db < /root/dump.sql