Skip to content

feat: run CHECKPOINT before smart and fast shutdowns#8867

Merged
mnencia merged 6 commits intomainfrom
dev/8865
Oct 20, 2025
Merged

feat: run CHECKPOINT before smart and fast shutdowns#8867
mnencia merged 6 commits intomainfrom
dev/8865

Conversation

@armru
Copy link
Member

@armru armru commented Oct 15, 2025

Run a CHECKPOINT before every PostgreSQL smart and fast shutdown request to reduce both shutdown duration and replica promotion time, especially in systems with a high checkpoint_timeout.

This follows the best-effort approach used in instance_controller.go: errors during the checkpoint are logged, but the shutdown proceeds regardless. The checkpoint step is skipped for immediate shutdown mode.

Closes #8865

@armru armru requested a review from a team as a code owner October 15, 2025 12:48
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 labels Oct 15, 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

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement 🪄 New feature or request labels Oct 15, 2025
@armru armru 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.25 release-1.26 release-1.27 labels Oct 15, 2025
@armru
Copy link
Member Author

armru commented Oct 15, 2025

/test limit=local

@github-actions
Copy link
Contributor

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

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 15, 2025
@gbartolini
Copy link
Contributor

This should be backported as it is a minor change that prevents interference with some existing Postgres configurations.

@gbartolini gbartolini added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.26 release-1.27 and removed do not backport This PR must not be backported - it will be in the next minor release labels Oct 15, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 16, 2025
@armru armru force-pushed the dev/8865 branch 6 times, most recently from f1c4b8b to 157c727 Compare October 16, 2025 08:02
@armru
Copy link
Member Author

armru commented Oct 16, 2025

/test limit=local

@github-actions
Copy link
Contributor

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

@gbartolini gbartolini requested a review from jsilvela as a code owner October 16, 2025 15:53
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 17, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 18, 2025
Comment on lines -599 to -609
db, err := r.instance.GetSuperUserDB()
if err != nil {
contextLogger.Error(err, "Cannot connect to primary server")
} else {
_, err = db.Exec("CHECKPOINT")
if err != nil {
contextLogger.Error(err, "Error while requesting a checkpoint")
}
}

contextLogger.Info("This is an old primary node. Shutting it down to get it demoted to a replica")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mnencia @armru I have removed this piece of code, as now the CHECKPOINT is embedded in the inner Shutdown procedure of the instance manager.

@gbartolini gbartolini changed the title feat: add checkpoint before PostgreSQL shutdown feat: run CHECKPOINT before smart and fast shutdowns Oct 18, 2025
@gbartolini
Copy link
Contributor

/test

@github-actions
Copy link
Contributor

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

@gbartolini gbartolini requested a review from mnencia October 20, 2025 03:29
armru and others added 6 commits October 20, 2025 13:53
Issue CHECKPOINT before shutdown to reduce shutdown time and subsequent
replica promotion time for systems with high checkpoint_timeout.

Follows best-effort pattern from instance_controller.go - logs errors
but continues with shutdown. Skips checkpoint for immediate mode.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
@mnencia mnencia merged commit d7b98ad into main Oct 20, 2025
35 checks passed
@mnencia mnencia deleted the dev/8865 branch October 20, 2025 12:47
cnpg-bot pushed a commit that referenced this pull request Oct 20, 2025
Run a `CHECKPOINT` before every PostgreSQL `smart` and `fast` shutdown
request to reduce both shutdown duration and replica promotion time,
especially in systems with a high `checkpoint_timeout`.

This follows the best-effort approach used in `instance_controller.go`:
errors during the checkpoint are logged, but the shutdown proceeds
regardless. The checkpoint step is skipped for `immediate` shutdown
mode.

Closes #8865

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
(cherry picked from commit d7b98ad)
cnpg-bot pushed a commit that referenced this pull request Oct 20, 2025
Run a `CHECKPOINT` before every PostgreSQL `smart` and `fast` shutdown
request to reduce both shutdown duration and replica promotion time,
especially in systems with a high `checkpoint_timeout`.

This follows the best-effort approach used in `instance_controller.go`:
errors during the checkpoint are logged, but the shutdown proceeds
regardless. The checkpoint step is skipped for `immediate` shutdown
mode.

Closes #8865

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
(cherry picked from commit d7b98ad)
cnpg-bot pushed a commit that referenced this pull request Oct 20, 2025
Run a `CHECKPOINT` before every PostgreSQL `smart` and `fast` shutdown
request to reduce both shutdown duration and replica promotion time,
especially in systems with a high `checkpoint_timeout`.

This follows the best-effort approach used in `instance_controller.go`:
errors during the checkpoint are logged, but the shutdown proceeds
regardless. The checkpoint step is skipped for `immediate` shutdown
mode.

Closes #8865

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
(cherry picked from commit d7b98ad)
THE-BRAHMA pushed a commit to THE-BRAHMA/cloudnative-pg that referenced this pull request Oct 30, 2025
…ve-pg#8867)

Run a `CHECKPOINT` before every PostgreSQL `smart` and `fast` shutdown
request to reduce both shutdown duration and replica promotion time,
especially in systems with a high `checkpoint_timeout`.

This follows the best-effort approach used in `instance_controller.go`:
errors during the checkpoint are logged, but the shutdown proceeds
regardless. The checkpoint step is skipped for `immediate` shutdown
mode.

Closes cloudnative-pg#8865

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
Signed-off-by: theBrahma <office.utpal.brahma@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases enhancement 🪄 New feature or request lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.25 release-1.26 release-1.27 size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Issue a CHECKPOINT before shutting down

4 participants