Repository navigation
feat(instance-manager): let standbys on the WAL archive retry streaming - #11868
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/42239135804 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/42263633339 |
|
Tested this on our staging AKS cluster today, with and without the patch. Short version: it fixes the stuck-on-archive standby for us, including the stuck Build: Stack: CNPG 1.30.1, plugin-barman-cloud v0.15.1 ( Rig, modelled on the PR's e2e fixture: a 2-instance source cluster plus a 1-instance replica cluster bootstrapped with Without the patch (stock 1.30.1)
With the patch (same clusters, same load)
Steady state afterwards: no forced failures logged while standbys were streaming, and the state file under One data point for the red e2e: in all three patched runs the gap between the first forced failure and Happy to re-run with different settings if useful. We're keeping this build on staging for a soak; details and raw observation logs are in our tracker if anyone wants them. |
|
Thanks for testing, and you were right about the red e2e. At one WAL file per second, a one-minute delay put the replica about 55 files behind, while the source keeps only 32 after a checkpoint, so streaming failed with |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/42610268784 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/42804542588 |
19686e9 to
8e52857
Compare
a7f3e3d to
dc52e51
Compare
|
/test |
|
@gbartolini, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/42974855241 |
621aac3 to
1cfe7c5
Compare
PostgreSQL moves a standby from the WAL archive to streaming replication only when restore_command fails. While the archive keeps up with the standby, that never happens, and the standby can stay on archive recovery indefinitely, with no WAL receiver, an inactive replication slot and no role in synchronous replication. After 30 seconds of continuous WAL restores, wal-restore now fails every request for a WAL segment for 5 seconds, before calling any plugin. A single failure is not enough from PostgreSQL 15 on, as a restore that fails while prefetching WAL is retried before PostgreSQL considers streaming. When the standby is back on the archive soon after, streaming did not hold and the interval doubles, up to 5 minutes. The failure is never forced in rewind mode, outside standby mode, without a streaming source, on the instance the operator is promoting, or while a promotion is pending: a pending pg_ctl promote waits for a failed restore, and would then end the recovery before replaying the WAL still in the archive. Nor is it forced for a WAL file already prefetched into the spool, which would stay there once the standby streams. Closes #11808 Signed-off-by: Armando Ruocco <[email protected]>
…ention The replica cluster of the streaming retry e2e replayed the WAL one minute after the source wrote it, one WAL file per second. When it tried streaming, it asked the source for a WAL file about 55 files behind, while the source, with no replication slot for it and the default wal_keep_size of 512MB, keeps only 32 of them after a checkpoint. Depending on when the checkpoint ended, streaming failed, and the replica went back to the archive and waited longer before the next try. A 20-second delay keeps the replica about 17 WAL files behind: within the retention of the source, and still behind the archive. At this rate, pg_wal grows to about 1.1GB on both clusters, more than their 1Gi volumes hold where the size is enforced: they now get 2Gi. Signed-off-by: Armando Ruocco <[email protected]>
…ource The source of the streaming retry e2e has a single instance, so no standby clone completes a WAL file after the bootstrap. On PostgreSQL 14 the first WAL file stays open until archive_timeout, five minutes by default, and the ContinuousArchiving condition never appeared within the 180 seconds the e2e waits for it. The e2e now switches a WAL file and waits for it in the object store before checking the condition, as the other single-instance plugin e2e already does. Signed-off-by: Armando Ruocco <[email protected]>
Tell whether streaming replication held by the WAL file the standby asks for once the forced failures end: a different file means the standby moved on by streaming, so the interval starts over; the same file means streaming did not hold, so the interval doubles. The idle gap is kept as a fallback. Previously a standby that streamed for just under the idle gap was penalized like one that failed to stream at all. Signed-off-by: Gabriele Bartolini <[email protected]>
…ry_interval The forced failures last a fixed 5 seconds, the default value of wal_retrieve_retry_interval, which suggests a link between the two. There is none: PostgreSQL retries a failed restore right away, and the parameter only delays the return to the archive when streaming replication cannot start. Signed-off-by: Armando Ruocco <[email protected]>
After a failed streaming attempt, PostgreSQL can ask again for the segment before the one that failed. Only a later segment tells that the standby moved on by streaming, so compare the names by order instead of by equality, and back off on the same or an earlier one. Signed-off-by: Gabriele Bartolini <[email protected]>
Name restore_command in the log line and in the error, log the interval with its unit instead of a bare number, and add the failure window. Rename ErrStreamingRetry to ErrForcedRestoreFailure, as it is not an error of streaming replication, FailedWAL to ForcedFailureWAL, as the file is not bad: it is restored later or received by streaming, and streamingRetryIdleGap to streamingRetryResetAfter, which says what it does. Explain in the comments why only a later WAL file counts as streaming progress, and why the pause is skipped. Signed-off-by: Gabriele Bartolini <[email protected]>
Leave out the internals that users do not need: how long restore_command fails, how it relates to wal_retrieve_retry_interval, and when the interval starts over. Link the section from the hybrid approach of the replica cluster documentation. Signed-off-by: Gabriele Bartolini <[email protected]>
1cfe7c5 to
fa53ab2
Compare
Signed-off-by: Leonardo Cecchi <[email protected]>
|
Given that we are exceptionally releasing 1.30.2 due to the new PostgreSQL version, I suggest we backport this. |
…ng (#11868) PostgreSQL moves a standby from the WAL archive to streaming only when `restore_command` fails. While the archive keeps up, that never happens: the standby stays on the archive with no WAL receiver, an inactive slot and no part in synchronous replication. After 30 seconds of continuous restores, `wal-restore` now fails every WAL segment request for 5 seconds, before calling any plugin. A single failure is not enough since PostgreSQL 15, which retries a restore that fails while prefetching. If the standby is back on the archive soon after, the interval doubles, up to 5 minutes. The failure is never forced in rewind mode, outside standby mode, without a streaming source, or while a promotion is pending (a `promote` file, or the operator promoting the instance): the promotion would then skip the WAL still in the archive. Nor is it forced for a WAL file already prefetched into the spool, which would stay there once the standby streams. When the source is unreachable, each try pauses the replay until the connection fails: about 6 seconds if refused, up to the TCP connect timeout if the host does not answer and `connect_timeout` is not set. The other instances of a replica cluster stream from the designated primary. Before 18.6, 17.11, 16.15, 15.19 and 14.24, an upstream bug can make that connection fail with "requested starting point ... is ahead of the WAL flush position", and PostgreSQL goes back to the archive, as it does today. The `Wal-restore in parallel` e2e runs `wal-restore` by hand on a streaming standby, up to 16 seconds after the first restore of the standby on KIND. It now disables the retry, which a slower run would trip. The counter proposed in the issue is left out, to avoid adding a metric to the public API. Closes #11808 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]>
…ng (#11868) PostgreSQL moves a standby from the WAL archive to streaming only when `restore_command` fails. While the archive keeps up, that never happens: the standby stays on the archive with no WAL receiver, an inactive slot and no part in synchronous replication. After 30 seconds of continuous restores, `wal-restore` now fails every WAL segment request for 5 seconds, before calling any plugin. A single failure is not enough since PostgreSQL 15, which retries a restore that fails while prefetching. If the standby is back on the archive soon after, the interval doubles, up to 5 minutes. The failure is never forced in rewind mode, outside standby mode, without a streaming source, or while a promotion is pending (a `promote` file, or the operator promoting the instance): the promotion would then skip the WAL still in the archive. Nor is it forced for a WAL file already prefetched into the spool, which would stay there once the standby streams. When the source is unreachable, each try pauses the replay until the connection fails: about 6 seconds if refused, up to the TCP connect timeout if the host does not answer and `connect_timeout` is not set. The other instances of a replica cluster stream from the designated primary. Before 18.6, 17.11, 16.15, 15.19 and 14.24, an upstream bug can make that connection fail with "requested starting point ... is ahead of the WAL flush position", and PostgreSQL goes back to the archive, as it does today. The `Wal-restore in parallel` e2e runs `wal-restore` by hand on a streaming standby, up to 16 seconds after the first restore of the standby on KIND. It now disables the retry, which a slower run would trip. The counter proposed in the issue is left out, to avoid adding a metric to the public API. Closes #11808 Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit bc0889a)
Drop the link to the release notes tracking issue from the PostgreSQL 18.7 entry, mark #11868 and #11935 as backported to 1.28, and add the contributor handles and requeue forms to the spellcheck wordlist. Signed-off-by: Marco Nenciarini <[email protected]>
PostgreSQL moves a standby from the WAL archive to streaming only when
restore_commandfails. While the archive keeps up, that never happens: the standby stays on the archive with no WAL receiver, an inactive slot and no part in synchronous replication.After 30 seconds of continuous restores,
wal-restorenow fails every WAL segment request for 5 seconds, before calling any plugin. A single failure is not enough since PostgreSQL 15, which retries a restore that fails while prefetching. If the standby is back on the archive soon after, the interval doubles, up to 5 minutes.The failure is never forced in rewind mode, outside standby mode, without a streaming source, or while a promotion is pending (a
promotefile, or the operator promoting the instance): the promotion would then skip the WAL still in the archive. Nor is it forced for a WAL file already prefetched into the spool, which would stay there once the standby streams.When the source is unreachable, each try pauses the replay until the connection fails: about 6 seconds if refused, up to the TCP connect timeout if the host does not answer and
connect_timeoutis not set.The other instances of a replica cluster stream from the designated primary. Before 18.6, 17.11, 16.15, 15.19 and 14.24, an upstream bug can make that connection fail with "requested starting point ... is ahead of the WAL flush position", and PostgreSQL goes back to the archive, as it does today.
The
Wal-restore in parallele2e runswal-restoreby hand on a streaming standby, up to 16 seconds after the first restore of the standby on KIND. It now disables the retry, which a slower run would trip.The counter proposed in the issue is left out, to avoid adding a metric to the public API.
Closes #11808