pg.ddx.io  patroni/patroni GitHub issues and pull requests  
help / color / mirror / Atom feed
From: mdzhigarov (@mdzhigarov) <noreply+mdzhigarov@github.com>
To: patroni/patroni <noreply+patroni-patroni@github.com>
Subject: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
Date: Mon, 16 Nov 2026 13:18:52 +0000
Message-ID: <gh-patroni-patroni-3784@github.com> (raw)

Fixes #3783

On PostgreSQL 12+ `restore_command` ends up in `postgresql.conf` only inside the `# recovery.conf` block, which is written only while the node has recovery parameters (is a standby). A primary that bootstrapped the cluster, or a former primary after crash recovery (`remove_recovery_conf()`), has no `restore_command` in its config files. `Rewind.pg_rewind()` reads it with `postgres -C restore_command`, gets an empty value and neither passes `--restore-target-wal` nor tries `_fetch_missing_wal()`. If the WAL that `pg_rewind` needs is only in the archive, the rewind fails and the node is started on its diverged timeline.

This adds `ConfigHandler.write_restore_command()`, which writes `restore_command` (of the remote member for the standby cluster leader, otherwise from `postgresql.recovery_conf`) to `postgresql.conf`, and calls it from `Rewind.execute()` right before `pg_rewind`.

Tests:
- `test_write_restore_command`: the local command for a `Leader`, the remote member's command for a `RemoteMember` (falling back to the local one), and no rewrite when nothing is configured.
- `test_execute_writes_restore_command`: `execute()` writes it before calling `pg_rewind()`.
- `test_pg_rewind_restore_target_wal`: `--restore-target-wal` is used on 14/15/18 when `restore_command` is visible to `postgres -C`, and not when it is empty.

Full test suite and flake8 pass locally. I also ran the scenario from #3783 (2 members, Kubernetes DCS, PostgreSQL 18.6) with this change: `pg_rewind` restores the missing file from the archive, exits 0, and the node follows the new primary.


view thread (15+ messages)  latest in thread

Message-ID: <gh-patroni-patroni-3784@github.com>
Permalink:  ../gh-patroni-patroni-3784@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox