wikiti
4/19/2017 - 11:15 AM

Backup and restore in PostgreSQL

Backup and restore in PostgreSQL using plain-text backups.

# List databases
sudo su postgres
psql
\list

# Create a plain-text backup
sudo su postgres
pg_dump <database_name> > <file>

# Example
pg_dump geartranslations_development > /tmp/backup.sql


# Restore a plain-text backup
# TABLES THAT ALREADY EXIST WILL NOT BE MODIFIED.
sudo su postgres
psql < <file>

# Example
psql < /tmp/backup.sql