K8SPG-1073: Remove restore_command when backups are disabled#1673
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates pgBackRest-related PostgreSQL parameter generation so Patroni does not configure restore_command when backups are disabled, preventing Postgres from attempting (and failing) WAL archive restores when no repository exists.
Changes:
- Omit
restore_commandfrom Patroni mandatory parameters when backups are disabled, unless the user explicitly overrides it. - Add unit test coverage for the “backups disabled” behavior, including override and standby-repo scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/pgbackrest/postgres.go | Conditionally adds restore_command only when backups are enabled or user-overridden (standby repo still forces it). |
| internal/pgbackrest/postgres_test.go | Adds a test case ensuring restore_command is omitted when backups are disabled, while preserving override and standby behavior. |
| // didn't. Leave restore_command unset so Postgres relies on streaming | ||
| // replication and local WAL only -- unless the user explicitly configured | ||
| // their own restore_command. |
|
@yoav-katz monitoring tests are failing repeatedly but I doubt it's related to your changes. we'll check. |
|
the same tests are failing in another PR I opened #1647 |
commit: 21b52c7 |
|
@yoav-katz thank you for the contribution. |
CHANGE DESCRIPTION
Problem:
When
spec.backups.enabled: falseis set, the operator still configures Patroni'srestore_commandto invoke pgBackRest (pgbackrest --stanza=<name> archive-get %f "%p"), even though no backup repository exists. Any time a replica needs a WAL segment it can't get via streaming replication, Postgres calls this command, which fails because there's no valid stanza/repo — instead of falling back cleanly to "no WAL available from archive."Cause:
internal/pgbackrest/postgres.go'sPostgreSQL()function already neutralizesarchive_commandwhen backups are disabled (sets it to a no-optrue), but the equivalent handling was missing forrestore_command— it was built and added to the Patroni mandatory parameter set unconditionally, with nobackupsEnabledcheck at all.Solution:
restore_commandis no longer set when backups are disabled. Unlikearchive_command, it can't simply be pointed at a no-op placeholder liketrue: Postgres treats a zero exit status fromrestore_commandas "the file was placed at %p," so a placeholder that always succeeds would make Postgres believe WAL recovery succeeded when it didn't, risking a crash or silent gap. Instead,restore_commandis omitted entirely in this case, so Postgres relies purely on streaming replication and local WAL. An explicit user override ofrestore_commandviaspec.patroni.dynamicConfigurationis still respected regardless ofbackups.enabled, since that reflects an intentional choice by the user.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability