postgresql Backup and Restore Restoring backups

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

psql < backup.sql

A safer alternative uses -1 to wrap the restore in a transaction. The -f specifies the filename rather than using shell redirection.

psql -1f backup.sql

Custom format files must be restored using pg_restore with the -d option to specify the database:

pg_restore -d DATABASE DATABASE.pgsql

The custom format can also be converted back to SQL:

pg_restore backup.pgsql > backup.sql

Usage of the custom format is recommended because you can choose which things to restore and optionally enable parallel processing.

You may need to do a pg_dump followed by a pg_restore if you upgrade from one postgresql release to a newer one.



Got any postgresql Question?