Clone a PG Cluster
Cloning restores production history into another cluster and leaves the production cluster unchanged. This makes cloning a useful recovery method with less risk to production. You can recover accidentally deleted data from the clone, validate backups in a drill, or inspect a historical state. You can also reset a test environment to a production snapshot.
The target must have access to the source backup repository and use a compatible PostgreSQL major version. Recovery may overwrite the target. In a shared Silo/S3 repository, a stanza isolates each cluster’s backups. Targets with the required credentials can access these backups.
Inspect the target topology with pig pg list <target-cluster>.
Verify the source stanza’s recent backups and recovery window with pig pb info.
Before the restore, have the operator confirm the exact source cluster, target cluster, and recovery point.
Recovery overwrites existing data on the target.
Production work requires a maintenance window and an independently verified backup.
Clone an Existing Cluster
Assume the four-node sandbox contains pg-meta and pg-test, sharing a Silo repository.
To reset pg-test to the latest state of pg-meta, point pg_pitr to the pg-meta stanza:
Add a recovery target to clone any state inside the recovery window. For example, reset to 15:30 on December 26, 2025:
These cross-cluster examples set archive: false to keep the exploratory recovery from archiving under the target stanza.
After Patroni takes control, complete the stanza and archive cleanup below.
The target may also be a newly initialized empty cluster, such as pg-meta2.
Use the normal cluster creation procedure to create it.
Then perform cross-cluster PITR.
pgBackRest restore uses delta mode and rewrites only files that differ from the backup. Repeated drills, or a target already synchronized through a standby cluster, can therefore restore much faster than a first full restore.
For accidental deletion, validate the clone and use pg_dump to export only the affected tables or database back into production.
An in-place rollback of the entire production cluster should be the last resort, not the first response.
Post-Clone Cleanup
The clone contains the source cluster’s data, while the target stanza may still record the target’s old PostgreSQL system identifier. pgBackRest refuses a backup when the identifiers do not match, preventing the new cluster from contaminating the source history.
After you validate the clone, complete these steps. A cluster restart changes the running service. First inspect the primary and replication state, schedule the maintenance window, and obtain explicit approval.
Until you complete these steps, scheduled backups can fail the identity check.
A clone restored with archive: false produces no new WAL archive:
Rebuild Backup Identity
stanza-upgrade lets the new cluster continue writing under its existing stanza.
If the clone needs a completely independent backup history, rebuild the stanza instead.
Declarative workflow:
Equivalent low-level workflow:
Before deletion, check recent backups and retain any required independent recovery copy.
Have the operator confirm the exact pg-test stanza.
Object-locked versions can remain and continue to consume storage.
A successful deletion command does not prove that it physically erased every underlying version.
Online Copies: Standby Clusters
A PITR clone is a static snapshot. Use a streaming-replication standby cluster for an online copy that follows the source continuously. Use a delayed cluster for a fixed rollback window, such as one hour.
The three methods complement each other. Standby clusters provide a live copy. Delayed clusters preserve a fixed delay. PITR clones provide any historical state inside the recovery window and do not require an existing online replica.
Restore Drills
A clone provides an end-to-end restore drill without changes to production. It overwrites the designated drill target. Run one quarterly and after major backup changes:
- Select a point inside the production recovery window.
- Restore it into the drill cluster and record elapsed time as the measured PITR RTO.
- Validate integrity with authorized row-count checks, critical-table checks, and application connectivity.
- Complete post-clone cleanup and verify that the drill cluster can create a new backup.
- Record timing, failures, and any difference between the runbook and reality.
See Manual Recovery for a sandbox exercise using pgBackRest primitives, or Fork an Instance for an XFS snapshot-based local test copy.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)