Skip to content

feat: startup and readiness probes for replicas#6623

Merged
gbartolini merged 15 commits intocloudnative-pg:mainfrom
leonardoce:readiness
Mar 10, 2025
Merged

feat: startup and readiness probes for replicas#6623
gbartolini merged 15 commits intocloudnative-pg:mainfrom
leonardoce:readiness

Conversation

@leonardoce
Copy link
Contributor

@leonardoce leonardoce commented Jan 18, 2025

Extend the startup and readiness probes configured through the .spec.probes.startup and .spec.probes.readiness sections by adding two additional parameters:

  • type: Defines the criteria for considering the probe successful. Accepted values include:
    • pg_isready: This setting marks the probe as successful when the pg_isready command exits with a status of 0. This is the default for both primary instances and replicas.
    • query: This setting marks the probe as successful when a basic query is executed locally on the postgres database.
    • streaming: This setting marks the probe successful when the replica starts streaming from its source and meets the specified lag requirements (details below).
  • lag: Specifies the maximum acceptable replication lag, measured in bytes (expressed using Kubernetes quantities). This parameter is applicable only when type is set to streaming. If the lag parameter is not specified, the replica is considered successfully started/ready as soon as it begins streaming.

Consequently, the liveness probe has been streamlined to verify solely that the instance manager is operational, without monitoring the underlying PostgreSQL instance.

Closes: #6621

Release Notes

Improved Startup and Readiness Probes for Replicas: Enhanced support for Kubernetes startup and readiness probes in PostgreSQL instances, providing greater control over replicas based on the streaming lag.

@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.22 release-1.24 release-1.25 labels Jan 18, 2025
@github-actions
Copy link
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@leonardoce leonardoce force-pushed the readiness branch 5 times, most recently from 3df3ab1 to e62c4be Compare January 18, 2025 13:12
@leonardoce leonardoce force-pushed the readiness branch 3 times, most recently from ba89383 to c756b27 Compare January 19, 2025 17:58
@gbartolini gbartolini added do not backport This PR must not be backported - it will be in the next minor release and removed backport-requested ◀️ This pull request should be backported to all supported releases release-1.22 release-1.24 release-1.25 labels Jan 21, 2025
@gbartolini gbartolini changed the title feat: startup probe configuration feat: startup probe for replicas Jan 21, 2025
@ardentperf
Copy link
Contributor

ardentperf commented Jan 22, 2025

IIUC, when replicas re-join they need to catch-up WAL - which has two effects:

  1. clients can connect as soon as the readiness probe succeeds and during catch-up their queries may get results that lag more than usual.
  2. the impetus for this PR: with preferred DataDurability (new feature in 1.25) all writes on the primary will completely hang during catch-up. the primary needs to write WAL synchronously and the latest WAL won't get acknowledged by the replica until it's caught up, leading to the hang on the primary.

+1 using a startup probe seems like a good idea

if someone is choosing preferred dataDurability then i don't think they would ever want the primary to hang. as a user, my hope is that replicas (re)joining a cluster should be as seamless as possible. a primary database hanging even briefly can be impactful on a large workload. I’m not sure we’d ever want a replica to be considered ready as soon as it starts streaming, when dataDurability is preferred. i suspect that users who choose preferred are specifically doing it because they want high availability.

my initial thought is that this should default to a small number of bytes and might not need to be configurable at all, unless as a setting for debugging or troubleshooting.

this would result in a slightly longer delay for replicas becoming ready even with dataDurability=required however it also means we eliminate the period on startup of higher-than-usual lag, which doesn't seem like a bad idea to me.

note: what i've written above is based on my understanding but i have not had time to test or verify it, so there might be mistakes. i haven't looked yet, but it could also be interesting to check how patroni approaches this.

@gbartolini
Copy link
Contributor

IIUC, when replicas re-join they need to catch-up WAL - which has two effects:

  1. clients can connect as soon as the readiness probe succeeds and during catch-up their queries may get results that lag more than usual.
  2. the impetus for this PR: with preferred DataDurability (new feature in 1.25) all writes on the primary will completely hang during catch-up. the primary needs to write WAL synchronously and the latest WAL won't get acknowledged by the replica until it's caught up, leading to the hang on the primary.

That's correct.

@leonardoce
Copy link
Contributor Author

@ardentperf
Copy link
Contributor

Is this PR in patroni solving a similar problem?

patroni/patroni#1786

@ardentperf
Copy link
Contributor

ardentperf commented Jan 24, 2025

interesting - from this recent pgcon talk it sounds like actually patroni might even still have the pause

https://youtu.be/CWrFPPG5USA?feature=shared&t=1190

i think in the talk he's focused on a 3rd node rejoining synchronous_standby_names with only 2 nodes required (so it doesn't cause the hang) - so i don't know for sure if there's any "special case" treatment for a synchronous cluster with only 2 nodes.

@leonardoce
Copy link
Contributor Author

interesting - from this recent pgcon talk it sounds like actually patroni might even still have the pause [...]

Yes. I think there is no solution this problem but only compromises.
Having the cluster paused reduces the time needed for the replica to get in sync.
If the cluster is not paused the replica will need more time.
If may not even be able to get in sync again - depending on the workload of the primary.

leonardoce and others added 13 commits March 10, 2025 11:53
Allow the user to configure the behavior of the startup probe, to be
choosen from the following list:

1. pg_isready
2. streaming, with optional lag limit

Closes: cloudnative-pg#6621

Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@gmail.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia
Copy link
Member

mnencia commented Mar 10, 2025

/test d=main tl=4

@github-actions
Copy link
Contributor

@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/13763633508

Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
@gbartolini gbartolini merged commit 3bafb17 into cloudnative-pg:main Mar 10, 2025
23 checks passed
l00ptr added a commit to l00ptr/cloudnative-pg that referenced this pull request Jul 11, 2025
When upgrading to 1.26 from previous version, PostgreSQL clusters are
restarted (even with in-place update enabled) due to change into the
Startup probe definition.

This issue appears to be a side effect of the improvements made to the
startup probe:
cloudnative-pg#6623
l00ptr added a commit to l00ptr/cloudnative-pg that referenced this pull request Jul 11, 2025
When upgrading to 1.26 from previous version, PostgreSQL clusters are
restarted (even with in-place update enabled) due to change into the
Startup probe definition.

This issue appears to be a side effect of the improvements made to the
startup probe:
cloudnative-pg#6623

Signed-off-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
sxd pushed a commit to l00ptr/cloudnative-pg that referenced this pull request Jul 14, 2025
When upgrading to 1.26 from previous version, PostgreSQL clusters are
restarted (even with in-place update enabled) due to change into the
Startup probe definition.

This issue appears to be a side effect of the improvements made to the
startup probe:
cloudnative-pg#6623

Signed-off-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
gbartolini pushed a commit to l00ptr/cloudnative-pg that referenced this pull request Jul 17, 2025
When upgrading to 1.26 from previous version, PostgreSQL clusters are
restarted (even with in-place update enabled) due to change into the
Startup probe definition.

This issue appears to be a side effect of the improvements made to the
startup probe:
cloudnative-pg#6623

Signed-off-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
gbartolini added a commit that referenced this pull request Jul 17, 2025
…8018)

When upgrading from a previous version to 1.26, PostgreSQL clusters will
be restarted even with in-place updates enabled, due to changes in the
Startup probe definition (PR #6623).

Closes #7727

Signed-off-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
mnencia pushed a commit that referenced this pull request Jul 18, 2025
…8018)

When upgrading from a previous version to 1.26, PostgreSQL clusters will
be restarted even with in-place updates enabled, due to changes in the
Startup probe definition (PR #6623).

Closes #7727

Signed-off-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Julian Vanden Broeck <julian.vandenbroeck@dalibo.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
(cherry picked from commit 48ddea1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release ok to merge 👌 This PR can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Startup and readiness probes for replicas

8 participants