Skip to content

feat(pitr): support POSTGRES_RECOVERY_TARGET_TYPE=immediate#74

Closed
paulocsanz wants to merge 1 commit into
mainfrom
pc/pitr-type-immediate
Closed

feat(pitr): support POSTGRES_RECOVERY_TARGET_TYPE=immediate#74
paulocsanz wants to merge 1 commit into
mainfrom
pc/pitr-type-immediate

Conversation

@paulocsanz
Copy link
Copy Markdown
Contributor

Summary

Adds a third recovery target type for restoring brand-new clusters that have a base backup but zero committed transactions to anchor recovery_target_time against.

  • New env var POSTGRES_RECOVERY_TARGET_TYPE=immediate. When set, the wrapper runs pgbackrest restore --type=immediate (no --target) and writes recovery_target = 'immediate' to postgresql.auto.conf. Postgres stops at end-of-base-backup consistency, no WAL replay past pg_backup_stop.
  • Precedence: _TYPE=immediate > _XID > _TIME.
  • Updates configure_pgbackrest_recovery and restore_from_pgbackrest_if_empty_volume gates to accept any of the three vars.

Context

Pairs with the mono picker change (which sets the env var when the probe flags noCommitsYet) and the postgres-ha sibling PR. Replaces the dead-end UX where a fresh cluster with a base backup couldn't be restored unless the user wrote a dummy row to seed pg_commit_ts/.

Test plan

  • Manual: fresh WAL_RECOVER_FROM_* + POSTGRES_RECOVERY_TARGET_TYPE=immediate on an empty volume — image runs pgbackrest restore --type=immediate, postgres comes up promoted at base-backup consistency.
  • Manual: existing _TIME-only path still works (regression).
  • Manual: existing _XID-over-_TIME precedence still works (regression).
  • bash -n wrapper.sh syntax-clean.

Add a third recovery target type for clusters where neither `_TIME` nor
`_XID` can anchor recovery — specifically, brand-new sources with zero
committed transactions. The picker (mono PR) sets this env var when the
probe sees `noCommitsYet`; the wrapper then runs `pgbackrest restore
--type=immediate` (no `--target` value) and writes
`recovery_target = 'immediate'` to `postgresql.auto.conf`. Postgres
stops at end-of-base-backup consistency with no WAL replay past
`pg_backup_stop`.

Precedence: `_TYPE=immediate` > `_XID` > `_TIME`. Existing `_TIME` and
`_XID` paths are unchanged.
@paulocsanz
Copy link
Copy Markdown
Contributor Author

Pivoting to a simpler approach: have the backup-watcher emit one transactional commit after each successful backup, so noCommitsYet stops being a real state. New PR will follow.

@paulocsanz paulocsanz closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant