Skip to content

feat: run CHECKPOINT before smart and fast shutdowns - #8867

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

mnencia merged 6 commits into
mainfrom
dev/8865

Conversation

@armru

@armru armru commented Oct 15, 2025 •

Copy link
Copy Markdown
Member

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 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 labels Oct 15, 2025
@github-actions

Copy link
Copy Markdown
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 labels Oct 15, 2025
@armru

armru commented Oct 15, 2025

Copy link
Copy Markdown
Member Author

/test limit=local

@github-actions

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
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 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
@github-actions

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

@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 <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
@mnencia
mnencia merged commit d7b98ad into main Oct 20, 2025
@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 <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Gabriele Bartolini <[email protected]>
(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 <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Gabriele Bartolini <[email protected]>
(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 <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Co-authored-by: Gabriele Bartolini <[email protected]>
(cherry picked from commit d7b98ad)
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 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