Version v3.7.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Restore
You can use the pre-configured pgbackrest to perform Point-in-Time Recovery (PITR) in Pigsty.
- Manually: PITR with the
pg-pitrhint script, do it manually, more flexible with more complexity. - Playbook: PITR with the
pgsql-pitr.ymlplaybook, automatic, but less flexible and more error-prone.
If you are very convenient with your configuration, you can use the fully automatic playbook, otherwise, consider do it step by step manually
Quick Start
If you want to roll back the pg-meta cluster to the previous timepoint, adding the pg_pitr:
Then run the pgsql-pitr.yml playbook, it will roll back the pg-meta cluster to the specified timepoint.
Restore PITR
The archive_mode will be disabled on recovered cluster to prevent unwanted WAL writes.
If the recovered database status is ok, you can enable the archive_mode and make a full backup.
Recovery Target
You can specify different types of recovery targets in pg_pitr, but they are mutually exclusive:
time: which time point to restore?name: restore to a named restore point (created bypg_create_restore_point)xid: restore to a specific transaction ID (TXID/XID)lsn: restore to a specific LSN (Log Sequence Number) point
The recovery type will be set accordingly if any of the above parameters is specified,
otherwise it will be set to latest (the end of the WAL archive stream).
The special immediate type can be used to instruct pgbackrest to minimize the recovery time by stop at the first consistent point.
Target Type
By Time
The most frequently used target is the time point; you can specify the time point to restore to:
Time should be a valid PostgreSQL TIMESTAMP, YYYY-MM-DD HH:MM:SS+TZ is recommended.
By Name
You can create a named restore point with pg_create_restore_point:
And use that named restore point in PITR:
By XID
If you have a transaction that accidentally deleted some data, the best way to recover is to restore the database to the state before that transaction.
You can find the exact transaction id from monitoring dashboard, or find it from TXID from the CSVLOG.
The target parameter is “inclusive” by default, which means the recovery will include the target point.
The exclusive flag will exclude that exact target, like the xid 24999 will be the last transaction being replayed
This only applies to time, xid, lsn recovery targets, check recovery_target_inclusive for details.
By LSN
PostgreSQL uses the LSN (Log Sequence Number) to identify the position of a WAL record. You can find it everywhere, like the PG LSN panel from Pigsty dashboards.
To restore to an exact point in the WAL stream, you may also specify the timeline parameter (default to latest)
Recovery Source
cluster: which cluster to restore? the currentpg_clusterwill be used by default, you can use any other cluster in the same pgbackrest reporepo: overwrite the backup repo, use the same format inpgbackrest_reposet: thelatestbackup set is used by default, but you can specify a specific pgbackrest backup by label
Pigsty will recover from the pgbackrest backup repository, if you are using a centralized backup repo (like MinIO/S3), you can specify another “stanza” (another cluster’s backup directory) to restore from.
The above configuration will mark the PITR procedure to use the pg-meta stanza.
You can also pass the pg_pitr parameter via CLI args:
You can also use these targets when pitr from another cluster:
Break Down
This approach is semi-automatic, you will participate in the PITR process to make key decisions.
For example, this configuration will restore the pg-meta cluster itself to the specified timepoint
Let’s do this one step by step:
PITR Definition
There are more options available in the pg_pitr parameter: