From 1a010460b0f2b2a383ba73f1f68efd59436451e5 Mon Sep 17 00:00:00 2001 From: Aleksandr Korchak Date: Thu, 19 Nov 2026 15:07:07 +0000 Subject: [PATCH v2 2/2] Add test for config reload during a fast checkpoint Add injection point "checkpoint-write-delay" at the end of CheckpointWriteDelay(), and a test that holds a fast 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 b4d92f0..09240d2 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -67,6 +67,7 @@ #include "storage/subsystems.h" #include "utils/acl.h" #include "utils/guc.h" +#include "utils/injection_point.h" #include "utils/memutils.h" #include "utils/resowner.h" #include "utils/wait_event.h" @@ -856,6 +857,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 cb3df6e..6d0e961 100644 --- a/src/test/recovery/meson.build +++ b/src/test/recovery/meson.build @@ -70,6 +70,7 @@ tests += { 't/059_remote_apply_status_interval.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..9dc95d6 --- /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: fast', $logstart), + 'fast 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: fast', $logstart), + 'checkpoint has completed'); + +$node->stop; + +done_testing(); -- 2.56.1