PostgreSQL 14 and earlier use exclusive mode backups, while PostgreSQL 15 and later should use non-exclusive mode backups. The functions have been renamed to reflect this change with:
-
pg_start_backup()andpg_stop_backup()being used to create storage snapshots in 14 and earlier. -
pg_backup_start()andpg_backup_stop()are used to create storage snapshots in 15 and later versions.
Volume snapshots for PostgreSQL should always be created as a part of a Protection Group. This ensures that if there are multiple volumes for a single PostgreSQL instance, all volumes are created consistently with one another at the same point in time.
A Protection Group allows for objects (volumes, hosts, etc) with similar characteristics to be grouped together for snapshot and protection manageability operations.
To create a storage snapshot of the PostgreSQL cluster two system administration functions are used:
-
pg_backup_start()- Prepares the server to begin an on-line backup. The only required parameter is an arbitrary user-defined label for the backup (Typically this would be the name under which the backup dump file will be stored.). If the optional second parameter is given as true, it specifies executingpg_backup_startas quickly as possible. This forces an immediate checkpoint which will cause a spike in I/O operations, slowing any concurrently executing queries. -
pg_backup_stop()- Finishes performing an on-line backup. The desired contents of the backup label file and the tablespace map file are returned as part of the result of the function and must be written to files in the backup area.
-
pg_start_backup()- This prepares the cluster for an on-line backup. A label for the backup is provided during execution which can be used to identify it at a later date. Two modes of operation are possible when using this function , exclusive or non-exclusive mode. -
pg_stop_backup()- This the finishing function calls for an exclusive or non-exclusive backup. If exclusive mode was specified when usingpg_start_backupthen this function removes the backup label and table space mapping file.
Step 1. Prepare the system for a storage snapshot
The function can be started with the following arguments:
-
PostgreSQL 14 and earlier -
pg_start_backup(‘Snapshot Name' [, fast boolean [, exclusive boolean ]]). -
PostgreSQL 15 and later-
pg_backup_start(‘Snapshot Name’, [, fast boolean]).
Executing pg_start_backup() will respond as follows if successful and respond with the write-ahead-log location:
-
PostgreSQL 14 and earlier:
postgres=# SELECT pg_start_backup('Snapshot01', true, true); pg_start_backup ----------------- A/4F000028 -
PostgreSQL 15 and later:
postgres=# SELECT pg_backup_start('Snapshot01',false); pg_backup_start ----------------- 75/11000028
Step 2. Take a volume snapshot on FlashArray
Once the system has been prepared for a storage snapshot the volume(s) identified in Matching Storage Locations to FlashArray Volumescan have a storage snapshot created of them using the following process:
In the FlashArray graphical user interface find the volumes relevant to the PostgreSQL cluster. This can be done in the Storage view under Volumes.
Navigate to the Protection view and select Protection groups.
Identify the section for Source Protection Groups and select the "+" in the top right hand corner:
In the Create Protection Group dialog provide a unique name and select Create.
Once the Protection Group has been created it will show up in the Source Protection Groups section.
Selecting the Protection Group will bring up the context view for it. Identify the section for Members and select the three ellipses in the top right hand corner. In the selection options that emerge select Add Volumes... to add volumes or Add Hosts.. to add the PostgreSQL host in question.
In the Add Members dialog identify the relevant objects to add. Once complete select Add.
Once the relevant members have been added to the Protection Group identify the section for Protection Group Snapshots and select the "+" in the top right hand corner top create a protection group snapshot.
In the Create Snapshot dialog provide the same same label used in preparing the PostgreSQL for a storage snapshot as the Optional Suffix. At this point retention and replication policies can be applied to this specific storage snapshot. Select Create when ready to create the protection group snapshot.
Once the Protection Group Snapshot has been created it will be shown in the Protection Group Snapshots for the Protection Group.
Step 3. Stop the Backup Operation
-
PostgreSQL 14 and earlier: After the storage snapshot has been created, the backup operation needs to be stopped using the
pg_stop_backupfunction. Exclusive mode must be set totrue.SELECT pg_stop_backup(true);The response should contain the write-ahead-log location if successful:
postgres=# SELECT pg_stop_backup(true); pg_stop_backup ---------------- (A/51000138,,) (1 row) -
PostgreSQL 15 and later: After the storage snapshot has been created, the backup operation needs to be stopped using the
pg_backup_stop()function:postgres=# SELECT pg_backup_stop(); pg_backup_stop ------------------------------------------------------------------------------- (75/11000138,"START WAL LOCATION: 75/11000028 (file 000000010000007500000011)+ CHECKPOINT LOCATION: 75/11000060 + BACKUP METHOD: streamed + BACKUP FROM: primary + START TIME: 2024-07-30 02:51:32 PDT + LABEL: Snapshot01 + START TIMELINE: 1 + ","") (1 row)