Create and restore PostgreSQL backups


To back up all the databases, create a dump file using the pg_dumpall tool.

$ pg_dumpall -U postgres > backup.sql

This operation could take some time depending on the database size. You may be asked to enter your password multiple times, as the tool will connect to each database individually.

NOTE: The steps previously described will only back up the data contained inside your database. There may be other files that you should take into account when performing a full backup, such as files that may have been uploaded to your application. Refer to your application’s documentation for more details.


Once you have the backup file, you can restore it with a command like the one below:

$ psql -U postgres -f backup.sql
Last modification September 11, 2018