Only dump

pg_dump –host HOST_1  –port 5432 –username SOURCE_db_username –schema SCHEMA_DO_BE_BACKED_UP –password –format custom –no-owner -x –no-privileges –blobs –verbose –file SCHEMA_BACKUP_DUMP_FILE.backup SOURCE_DB_NAME

Only Restore

Target database must exist.

pg_restore –host HOST_2 –port 5432 –username TARGET_db_username –dbname TARGET_DB_NAME –password –no-owner -x –no-privileges –jobs 2 –verbose SCHEMA_BACKUP_DUMP_FILE.backup

Dump and restore with data streaming

env PGPASSWORD=source_db_user_pass –host=HOST_1 –port=5432 –schema SCHEMA_DO_BE_BACKED_UP –username=”source_db_username” –format=custom –no-owner -x –no-privileges source_db_name | env PGPASSWORD=target_db_user_pass pg_restore –host=HOST_2 –no-privileges –no-owner –no-tablespaces –verbose –username=target_db_username –dbname=target_db_name –clean


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.