How to backup and restore PostgreSQL database
Answered
11
What is the command to backup and restore a PostgreSQL database?
L
Asked by
linux_expert
Bronze
•
311 rep
1 Answer
21
# Backup
pg_dump -U username -d database_name > backup.sql
# Compressed backup
pg_dump -U username -d database_name | gzip > backup.sql.gz
# Restore
psql -U username -d database_name < backup.sql
# Restore from compressed
gunzip -c backup.sql.gz | psql -U username -d database_name
# Custom format (recommended)
pg_dump -Fc -U username database_name > backup.dump
pg_restore -U username -d database_name backup.dump
S
Bronze
•
259 rep
Your Answer
You need to be logged in to answer questions.
Log In to Answer