RefLib

Reference library for AI

Back

postgresql_16:4.11.3.6 Tips and Examples

PostgreSQL 16 > Server Administration > Backup and Restore > Continuous Archiving and Point-in-Time Recovery (PITR) > Tips and Examples

Some tips for configuring continuous archiving are given here.

Standalone Hot Backups

It is possible to use PostgreSQL's backup facilities to produce standalone hot backups. These are backups that cannot be used for point-in-time recovery, yet are typically much faster to backup and restore than pg_dump dumps. (They are also much larger than pg_dump dumps, so in some cases the speed advantage might be negated.)

As with base backups, the easiest way to produce a standalone hot backup is to use the (see postgresql_16:7.2.8) tool. If you include the -X parameter when calling it, all the write-ahead log required to use the backup will be included in the backup automatically, and no special action is required to restore the backup.

Compressed Archive Logs

If archive storage size is a concern, you can use gzip to compress the archive files: archive_command = 'gzip < %p > /mnt/server/archivedir/%f.gz' You will then need to use gunzip during recovery: restore_command = 'gunzip < /mnt/server/archivedir/%f.gz > %p'

archive_command Scripts

Many people choose to use scripts to define their archive_command, so that their postgresql.conf entry looks very simple: archive_command = 'local_backup_script.sh "%p" "%f"' Using a separate script file is advisable any time you want to use more than a single command in the archiving process. This allows all complexity to be managed within the script, which can be written in a popular scripting language such as bash or perl.

Examples of requirements that might be solved within a script include: Copying data to secure off-site data storage Batching WAL files so that they are transferred every three hours, rather than one at a time Interfacing with other backup and recovery software Interfacing with monitoring software to report errors

Tip

When using an archive_command script, it's desirable to enable (see guc-logging-collector). Any messages written to stderr from the script will then appear in the database server log, allowing complex configurations to be diagnosed easily if they fail.

Back