From aded939a5d127cec4a6f40e35bcdb6e7b3a58af3 Mon Sep 17 00:00:00 2001 From: Alvie Rahman Date: Tue, 6 Jul 2021 16:28:58 +0100 Subject: [PATCH] update postgres backup process --- postgres.md | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/postgres.md b/postgres.md index fafe1ac..ed36256 100755 --- a/postgres.md +++ b/postgres.md @@ -71,7 +71,7 @@ changed since the first backup. - to enable WAL archiving: - 1. set `wal_level` to `archive` (or `hot_standby`) + 1. set `wal_level` to `replica` or higher 1. set `archive_mode` to `on` 1. set `archive_command` to the command to use to backup @@ -101,34 +101,11 @@ changed since the first backup. 1. make a base backup -### make a base backup +### make a base backup[^pg_basebackup] -1. ensure WAL archiving is enabled and working -2. issue the following command as superuser: +1. ensure that WAL archiving is working and set up properly. +1. Run `pg_basebackup -D - -F tar > backup.tar` - ``` - SELECT pg_start_backup('label'); - ``` - - - `label` is any string to uniquely identify backup operation, e.g. the full path where you - intend to put the backup dump file - - It does not matter which database within the cluster you connect to to issue this command -3. Perform the backup, using any convenient file-system-backup tool such as tar or cpio - (not pg_dump or pg_dumpall). It is neither necessary nor desirable to stop normal operation of - the database while you do this. -4. issue the following command as superuser: - - ``` - SELECT pg_stop_backup(); - ``` - - this terminates the backup mode and performs an automatic switch to the next WAL segment - - -> You can also use the pg_basebackup tool to take the backup, instead of manually copying the files. - This tool will do the equivalent of pg_start_backup(), copy and pg_stop_backup() steps - automatically, and transfers the backup over a regular PostgreSQL connection using the replication - protocol, instead of requiring file system level access. pg_basebackup does not interfere with - file system level backups taken using pg_start_backup()/pg_stop_backup(). [^c24]: https://www.postgresql.org/docs/9.1/backup-dump.html +[^pg_basebackup]: https://www.postgresql.org/docs/13/app-pgbasebackup.html