Search

PosgreSQL: backup with pg_dump

Dump database in bz2 file
pg_dump -U dbuser dbname | bzip2 -c > dumpfilename.bz2

Dump single table (structure and data) in bz2 file
pg_dump -U dbuser -t tablename -v dbname| bzip2 -c > dumpfilename.bz2



Dump single table (structure only) in sql file
pg_dump -s -t tablename db name -U dbuser > dumpfilename.sql

Dump single table (data only) in sql file
pg_dump -a -t tablename dbname -U dbuser > dump.sql

List all insert statement for a table in a sql file
pg_dump --column-inserts -t tablename dbname -U dbuser > dump.sql

Import dump from bz2 file
bunzip2 dumpfilename.bz2 -c | psql dbname 

Import dump from sql file
psql -U postgres mydatabase < dumpfilename.sql

Backup single table
CREATE  TABLE bktablename AS select * from tablename


No comments:

Post a Comment