pg.ddx.io patroni/patroni GitHub issues and pull requests
help / color / mirror / Atom feed[patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
15+ messages / 4 participants
[nested] [flat]
* [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-16 13:18 "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
0 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-16 13:18 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
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.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Keep restore_command in postgresql.conf on a primary for pg_rewind
@ 2026-11-16 13:18 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-16 13:18 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@mdzhigarov requested a review.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Keep restore_command in postgresql.conf on a primary for pg_rewind
@ 2026-11-16 13:18 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-16 13:18 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@mdzhigarov requested a review.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-16 15:40 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-11-16 15:40 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Problem indeed exists, but I would suggest solving it differently, by writing restore_command to postgresql.conf short before executing pg_rewind.
For that we need to add a function to patroni/postgresql/config.py:
```python
def write_restore_command(self, member: Union[Leader, RemoteMember]) -> None:
restore_command = isinstance(member, RemoteMember) and member.data.get('restore_command') \
or self.restore_command()
if restore_command:
self._recovery_params = CaseInsensitiveDict({'restore_command': restore_command})
self.write_postgresql_conf()
```
And call it from Rewind.execute()
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 07:03 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-17 07:03 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@mdzhigarov renamed this.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 07:03 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-17 07:03 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Thanks, that is cleaner. Reworked as you suggested: `write_restore_command()` in config.py, called from `Rewind.execute()` right before `pg_rewind`. Tests updated, and I re-ran the scenario from #3783: the rewind now restores the missing WAL from the archive and the node rejoins as a replica.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 09:22 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: codecov[bot] (bot) (@codecov[bot]) @ 2026-11-17 09:22 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
## [Codecov](https://app.codecov.io/gh/patroni/patroni/pull/3784?dropdown=coverage&src=pr&el=h1&utm_m...) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? [Let us know!](https://github.com/codecov/feedback/issues/255)
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 09:28 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-11-17 09:28 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/postgresql/config.py:1574)
One small nitpick - lets do an early exit when nothing to do to avoid unnecessary overwrite of postgresql.conf:
```suggestion
if self._postgresql.major_version < 120000:
return
restore_command = isinstance(member, RemoteMember) and member.data.get('restore_command') \
```
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 09:31 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-17 09:31 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
(on patroni/postgresql/config.py:1574)
Thanks, addressed.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784 (approved): Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-17 10:04 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: CyberDem0n (@CyberDem0n) @ 2026-11-17 10:04 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-19 13:45 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: mdzhigarov (@mdzhigarov) @ 2026-11-19 13:45 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
Hi, any ETA when will this get merged and potentially included in the next release?
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784 (approved): Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-19 17:47 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 17:47 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 17:48 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet applied label "bug".
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 17:48 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet closed this.
^ permalink raw [nested|flat] 15+ messages in thread
* Re: [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind
@ 2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
13 siblings, 0 replies; 15+ messages in thread
From: hughcapet (@hughcapet) @ 2026-11-19 17:48 UTC (permalink / raw)
To: patroni/patroni <noreply+patroni-patroni@github.com>
@hughcapet merged this (commit 12bab383e0c5).
^ permalink raw [nested|flat] 15+ messages in thread
end of thread, other threads:[~2026-11-19 17:48 UTC | newest]
Thread overview: 15+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 13:18 [patroni/patroni] PR #3784: Write restore_command to postgresql.conf before running pg_rewind "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-16 13:18 ` Re: [patroni/patroni] PR #3784: Keep restore_command in postgresql.conf on a primary for pg_rewind "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-16 13:18 ` Re: [patroni/patroni] PR #3784: Keep restore_command in postgresql.conf on a primary for pg_rewind "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-16 15:40 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-11-17 07:03 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-17 07:03 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-17 09:22 ` "codecov[bot] (bot) (@codecov[bot])" <noreply+codecov[bot]@github.com>
2026-11-17 09:28 ` "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-11-17 09:31 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-17 10:04 ` Re: [patroni/patroni] PR #3784 (approved): Write restore_command to postgresql.conf before running pg_rewind "CyberDem0n (@CyberDem0n)" <noreply+CyberDem0n@github.com>
2026-11-19 13:45 ` "mdzhigarov (@mdzhigarov)" <noreply+mdzhigarov@github.com>
2026-11-19 17:47 ` Re: [patroni/patroni] PR #3784 (approved): Write restore_command to postgresql.conf before running pg_rewind "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@github.com>
2026-11-19 17:48 ` "hughcapet (@hughcapet)" <noreply+hughcapet@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