Backing up the whole cluster

suggest change
$ pg_dumpall -f backup.sql

This works behind the scenes by making a connection to the server once for each database and executing pg_dump on it.

Sometimes you might set this up as a cron job and put the date in the filename:

$ pg_dumpall -f postgres-backup-$(date +%Y-%m-%d).sql

However, please note that this could produce large files on a daily basis. PostgreSQL has a much better mechanism for regular backups: WAL archives.

The output from pg_dumpall is sufficient to restore to an identically-configured Postgres instance, but the configuration files in $PGDATA (pg_hba.conf and postgresql.conf) are not part of the backup, so you’ll have to back them up separately.

postgres=# SELECT pg_start_backup('my-backup');
postgres=# SELECT pg_stop_backup();

To take a filesystem backup, you must use these functions to help ensure that Postgres is in a consistent state while the backup is prepared. The one-argument form is exclusive backup mode, removed in PostgreSQL 15. On PostgreSQL 15 and later, use pg_backup_start('my-backup') and pg_backup_stop(), and keep the backup label those functions return with the copy of the data directory.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents