Skip to content

Instantly share code, notes, and snippets.

@wikiti
Last active November 5, 2023 22:32
Show Gist options
  • Save wikiti/22ebd04115448aef786ad5c123dc666c to your computer and use it in GitHub Desktop.
Save wikiti/22ebd04115448aef786ad5c123dc666c to your computer and use it in GitHub Desktop.
Backup and restore in PostgreSQL using compressed backups.
# List databases
sudo su postgres
psql
\list
# Create a compressed backup
sudo su postgres
pg_dump -Fc <database_name> > <file>
# Example
pg_dump -Fc geartranslations_development > /tmp/backup.dump
# Restore a plain-text backup
# TABLES THAT ALREADY EXIST WILL NOT BE MODIFIED.
sudo su postgres
pg_restore -Fc -d <database_name> <backup_file>
# Example
pg_restore -Fc -d geartranslations_development /tmp/backup.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment