pgBackRest FULL backup status


Job details

Name: pgBackRest FULL backup status
Platform: Postgres
Category: Availability
Description: Monitors the status and recency of PostgreSQL FULL backups performed with pgBackRest.
Long description: Checks the status of pgBackRest backups for PostgreSQL instances by analyzing available backup metadata. The job ensures that recent FULL backups exist and meet expectations regarding freshness and retention, helping to detect potential backup issues early.
Version: 1.0
Default schedule: 10 6 * *
Requires engine install: Yes
Compatibility tag: .[type=‘instance’ & databasetype=‘postgres’]/.[hasengine=‘YES’ & is_awsrds = ‘0′ & maj_version > ‘11′ ]

Parameters

Name Default value Description
alarm threshold 48 Specifies the maximum number of hours allowed since the last backup before an alarm is triggered. This acts as a critical threshold indicating that backups are significantly overdue and may require immediate attention.
warning threshold 24 Specifies the maximum number of hours allowed since the last backup before a warning is triggered. If the time since the last backup exceeds this threshold, the job will return a warning status.
history threshold 120 Defines the number of days that backup statistics should be retained in the history table. This ensures long-term tracking of backup size and timing trends for auditing or analysis purposes.
pgbackrest output table dbwatch_cc.pgbackrest_backup_log Specifies the name of the table (in schema_name.table_name format) where the output from the pgbackrest info command will be stored. This allows the job to persist raw backup metadata for further processing. This table does not need to reside in the dbwatch schema but must be accessible within the dbWatch monitored database.

Job Summary

Implementation Details

This job consists of several SQL statements and PL/pgSQL functions that perform a series of tasks:

Key SQL code snippets include:
bc. CREATE TABLE dbw_pgbackrest_full_backup_status_data (id SERIAL PRIMARY KEY, stanza TEXT NOT NULL, backup_type TEXT NOT NULL, backup_label TEXT NOT NULL, timestamp_start TIMESTAMPTZ NOT NULL, timestamp_stop TIMESTAMPTZ NOT NULL, wal_start TEXT NOT NULL, wal_stop TEXT NOT NULL, db_size TEXT NOT NULL, db_backup_size TEXT NOT NULL, repo_backup_set_size TEXT NOT NULL, repo_backup_size TEXT NOT NULL, insert_time TIMESTAMPTZ DEFAULT now());

CREATE OR REPLACE FUNCTION dbw_pgbackrest_full_backup_status (taskId int) RETURNS void AS -- Function details omitted for brevity.

Backup Job Dependencies

This monitoring job depends on a set of objects and tables. The dependencies ensure that data regarding backup operations is managed correctly, including the creation and cleanup of necessary database objects:
|_. Object |_. Object Type |_. Cleanup on Fail |_. Description |
| dbw_pgbackrest_full_backup_status | Function | Yes | Main function to check backup status |
| dbw_pgbackrest_full_backup_status_data | Table | Yes | Stores current backup data |
| dbw_pgbackrest_full_backup_status_histr | Table | Yes | Stores historical backup size data |

Cleanup code on job failure includes:
bc. DROP PROCEDURE dbw_pgbackrest_full_backup_status(integer);
bc. DROP TABLE dbw_pgbackrest_full_backup_status_data;

Reporting

The job provides reports that help in evaluating the backup status:

The job also has a visual representation chart in the dbWatch report that plots backup sizes against backup start times to easily visualize backup trends.