From b2d58a602fe9c1039a6e32afde81839012f192b4 Mon Sep 17 00:00:00 2001 From: Aleksandr Korchak Date: Thu, 19 Nov 2026 15:08:07 +0000 Subject: [PATCH REL_18 v2 2/2] Add test for config reload during an immediate checkpoint Add injection point "checkpoint-write-delay" at the end of CheckpointWriteDelay(), and a test that holds an immediate checkpoint on it and changes synchronous_standby_names with no standby connected. The change must take effect before the checkpoint completes: a commit starts waiting in SyncRep once the setting is enabled, and is released once it is disabled again. Without the previous commit, the test times out waiting for the checkpointer to apply the new configuration. Author: Aleksandr Korchak Discussion: https://postgr.es/m/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com Backpatch-through: 18 --- src/backend/postmaster/checkpointer.c | 3 + src/test/recovery/meson.build | 1 + .../t/062_checkpoint_config_reload.pl | 98 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/test/recovery/t/062_checkpoint_config_reload.pl diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 3d65ad2..6bd33cf 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -62,6 +62,7 @@ #include "storage/smgr.h" #include "storage/spin.h" #include "utils/guc.h" +#include "utils/injection_point.h" #include "utils/memutils.h" #include "utils/resowner.h" @@ -838,6 +839,8 @@ CheckpointWriteDelay(int flags, double progress) /* Check for barrier events. */ if (ProcSignalBarrierPending) ProcessProcSignalBarrier(); + + INJECTION_POINT("checkpoint-write-delay", NULL); } /* diff --git a/src/test/recovery/meson.build b/src/test/recovery/meson.build index 005f06f..6f08eb2 100644 --- a/src/test/recovery/meson.build +++ b/src/test/recovery/meson.build @@ -64,6 +64,7 @@ tests += { 't/057_snapshot_commit_race.pl', 't/060_multixact_crashed_updater.pl', 't/061_recovery_target_prefetch.pl', + 't/062_checkpoint_config_reload.pl', ], }, } diff --git a/src/test/recovery/t/062_checkpoint_config_reload.pl b/src/test/recovery/t/062_checkpoint_config_reload.pl new file mode 100644 index 0000000..6fd69b5 --- /dev/null +++ b/src/test/recovery/t/062_checkpoint_config_reload.pl @@ -0,0 +1,98 @@ + +# Copyright (c) 2026, PostgreSQL Global Development Group + +use strict; +use warnings FATAL => 'all'; +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +if ($ENV{enable_injection_points} ne 'yes') +{ + plan skip_all => 'Injection points not supported by this build'; +} + +my $node = PostgreSQL::Test::Cluster->new('primary'); +$node->init(allows_streaming => 1); +$node->append_conf( + 'postgresql.conf', q[ +autovacuum = off +log_checkpoints = on +log_min_messages = debug2 +]); +$node->start; + +if (!$node->check_extension('injection_points')) +{ + plan skip_all => 'Extension injection_points not installed'; +} + +$node->safe_psql('postgres', 'CREATE EXTENSION injection_points'); +$node->safe_psql('postgres', + 'CREATE TABLE t AS SELECT generate_series(1, 100000) AS a'); + +my $logstart = -s $node->logfile; +$node->safe_psql('postgres', + "SELECT injection_points_attach('checkpoint-write-delay', 'wait')"); +my $checkpoint = $node->background_psql('postgres'); +$checkpoint->query_until( + qr/starting_checkpoint/, q( +\echo starting_checkpoint +CHECKPOINT; +)); +$node->wait_for_event('checkpointer', 'checkpoint-write-delay'); +ok($node->log_contains('checkpoint starting: immediate', $logstart), + 'immediate checkpoint has started'); + +sub change_during_checkpoint +{ + my ($value) = @_; + my $offset = -s $node->logfile; + + $node->safe_psql('postgres', + "ALTER SYSTEM SET synchronous_standby_names = '$value'"); + $node->reload; + $node->safe_psql('postgres', + "SELECT injection_points_wakeup('checkpoint-write-delay')"); + $node->wait_for_log( + qr/checkpointer updated shared memory configuration values/, $offset); + ok( !$node->log_contains('checkpoint complete', $logstart), + "synchronous_standby_names = '$value' applied before the checkpoint completed" + ); +} + +change_during_checkpoint('*'); +my $commit = $node->background_psql('postgres'); +$commit->query_until( + qr/committing/, q( +\echo committing +INSERT INTO t VALUES (0); +)); +ok( $node->poll_query_until( + 'postgres', + "SELECT count(*) = 1 FROM pg_stat_activity WHERE wait_event = 'SyncRep'" + ), + 'commit waits for the standby while the checkpoint is running'); + +change_during_checkpoint(''); +ok( $node->poll_query_until( + 'postgres', + "SELECT count(*) = 0 FROM pg_stat_activity WHERE wait_event = 'SyncRep'" + ), + 'waiting commit is released while the checkpoint is running'); +$commit->quit; + +ok(!$node->log_contains('checkpoint complete', $logstart), + 'checkpoint is still running'); + +$node->safe_psql('postgres', + "SELECT injection_points_detach('checkpoint-write-delay')"); +$node->safe_psql('postgres', + "SELECT injection_points_wakeup('checkpoint-write-delay')"); +$checkpoint->quit; +ok($node->log_contains('checkpoint complete', $logstart), + 'checkpoint has completed'); + +$node->stop; + +done_testing(); -- 2.56.1