Skip to content

Instantly share code, notes, and snippets.

@lnxph-devops-sareno
Created May 18, 2025 07:54
Show Gist options
  • Save lnxph-devops-sareno/1f295233376822dd646a23d159c9d64e to your computer and use it in GitHub Desktop.
Save lnxph-devops-sareno/1f295233376822dd646a23d159c9d64e to your computer and use it in GitHub Desktop.
PostgreSQL Dump/Restore (data only)

Create backup on the source database

Note:

Owner and privileges are excluded.

pg_dump -U src_db_user -h src-db.example.com -d src_db_name --no-owner --no-privileges -F c -f mybackup-yyyMMddHHmmss.dump

Restore backup to the destination database

Create backup first before restoring

pg_dump -U dst_db_user -h dst-db.example.com -d dst_db_name --no-owner --no-privileges -F c -f backup_before_restore-yyyMMddHHmmss.dump

Restore

pg_restore -U dst_db_user -h dst-db.example.com -d dst_db_name --no-owner --no-privileges --disable-triggers mybackup-yyyMMddHHmmss.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment