Skip to content

Instantly share code, notes, and snippets.

@edthrn
Last active July 23, 2019 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edthrn/622c7f157329268ea8b915b38a0d419f to your computer and use it in GitHub Desktop.
Save edthrn/622c7f157329268ea8b915b38a0d419f to your computer and use it in GitHub Desktop.
Sync content from one Postgres database to another

Say we have a database A hosted at my.first.database.com loaded with data, and we want to replicate this data over database B, located at my.second.database.com. We suppose database A and B have identical schemas, and both databases are accessible via port 5432.

Dump content from database A

 pg_dump --data-only \
 -h my.first.database.com \
 -U {database_user} \
 -f /tmp/dump.sql \
 -T={table pattern to exclude [optional]} \
 {database_name}

Load content into database B

psql \
-h my.second.database.com \
-U {db_user} \
{db_name} < /tmp/dump.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment