Postgres SQL: Backup/Copy and restore data between databases or servers


In the console, type

pg_dump -h -U username database_name -a -i -f output_filename.txt -t table_name_1 -t table_name_2 -t table_name_3

The switches used are:

Switch Description


Hostname of database.




Data only.


Ignore version difference between pg_dump and running database server.


Use INSERT instead of COPY.


Output filename.


Table name (can use more than once).

To restore the data back into the database, connect to it and then type:

\i output_filename.txt

This will execute the commands in the output file, inserting all the data into the database you're connected to.


Post a Comment

Leave your thoughts ...
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog