LinuxCommandLibrary

pg_verifybackup

Verify PostgreSQL backup integrity

TLDR

Verify a backup stored in a specific directory

$ pg_verifybackup [path/to/backup]
copy

Verify a backup showing progress information
$ pg_verifybackup [[-P|--progress]] [path/to/backup]
copy

Verify a backup and exit immediately on first error
$ pg_verifybackup [[-e|--exit-on-error]] [path/to/backup]
copy

Verify a backup ignoring specific files or directories
$ pg_verifybackup [[-i|--ignore]] [path/to/file_or_directory] [path/to/backup]
copy

Verify a backup with a manifest file in a different location
$ pg_verifybackup [[-m|--manifest-path]] [path/to/backup_manifest] [path/to/backup]
copy

Display help
$ pg_verifybackup [[-?|--help]]
copy

SYNOPSIS

pg_verifybackup [OPTION...] BACKUP

PARAMETERS

-D, --debug
    Output debug messages for detailed diagnostics

-L, --list
    List contents of the backup archive

--verify-checksums
    Verify checksums in all data files

--version
    Output version information and exit

--waldir=DIRECTORY
    Specify directory holding additional WAL files

-?, --help
    Show help message and exit

DESCRIPTION

pg_verifybackup is a PostgreSQL utility that checks the validity and integrity of backup archives created by pg_basebackup, supporting both plain directory and tar formats. It examines key components including WAL files, tablespace maps, and data files without requiring a full restore, saving time and resources. The tool detects corruption by verifying file structures, checksums (if enabled), and consistency of backup metadata.

Usage involves pointing it at an unmodified backup directory or tar file. It outputs a summary of verification results, listing any issues found. This is essential for production environments to confirm backup reliability before disasters. Debug mode provides detailed logs for troubleshooting, while list mode inventories contents. Note that it assumes backups are complete; partial or tampered archives will fail validation.

CAVEATS

Backup must be unmodified and complete; does not support compressed tar files or backups from before PostgreSQL 12. WAL verification limited unless --waldir specified. Exits with 0 on success, 1 on invalid backup, 2 on errors.

EXAMPLES

pg_verifybackup /path/to/backup_dir
pg_verifybackup --list --verify-checksums backup.tar

EXIT CODES

0: Valid backup
1: Backup invalid
2: Command error or usage issue

HISTORY

Introduced in PostgreSQL 12 (2019) to address need for non-restorative backup validation; enhanced in later versions with checksum support and WAL directory option.

SEE ALSO

Copied to clipboard