From e5bfbf770931e50861b66426eb3b976b0ae0d149 Mon Sep 17 00:00:00 2001 From: JoongHyuk Shin Date: Sun, 6 Sep 2026 13:37:00 +0900 Subject: [PATCH v2 2/2] Make recovery_min_apply_delay wait on recovery boundary records recovery_min_apply_delay delays only commit records, on the grounds that the effects of other records are not visible until the commit is applied. That does not hold for the file operations of database and tablespace commands. A delayed standby drops a database directory or creates a tablespace directory immediately, and only the catalog change waits for the delay. Use the timestamp of the recovery boundary record as the delay reference as well, so that these file operations wait for the configured delay like the commit does. Adjust the config.sgml paragraph that describes the commit-only behavior and add a test case to 005_replay_delay.pl. --- doc/src/sgml/config.sgml | 11 +++++++---- src/backend/access/transam/xlogrecovery.c | 24 ++++++++++++++--------- src/test/recovery/t/005_replay_delay.pl | 13 ++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 289058484ab..c10a597cf0a 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -5644,10 +5644,13 @@ ANY num_sync ( safe_psql('postgres', "CREATE DATABASE db_dropped"); # Take backup my $backup_name = 'my_backup'; @@ -55,6 +56,18 @@ $node_standby->poll_query_until('postgres', # the configured apply delay. cmp_ok(time() - $primary_insert_time, '>=', $delay, "standby applies WAL only after replication delay"); + +my $oid_dropped = $node_primary->safe_psql('postgres', + "SELECT oid FROM pg_database WHERE datname = 'db_dropped'"); +my $primary_drop_time = time(); +$node_primary->safe_psql('postgres', "DROP DATABASE db_dropped"); +$node_standby->poll_query_until('postgres', + "SELECT pg_stat_file('base/$oid_dropped', true) IS NULL") + or die "standby never removed the directory of db_dropped"; +cmp_ok(time() - $primary_drop_time, + '>=', $delay, + "standby removes database files only after replication delay"); + # Check that recovery can be paused or resumed expectedly. my $node_standby2 = PostgreSQL::Test::Cluster->new('standby2'); $node_standby2->init_from_backup($node_primary, $backup_name, -- 2.54.0