Dump and restore a postgres table

Dump a single postgres table:

pg_dump -U user_name -h localhost -t table_name --data-only db_name > data_dump.sql

You can truncate the table before doing the restore. Restore the table in the database:

psql -U user_name -h localhost db_name < data_dump.sql

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s