public inbox for [email protected]
help / color / mirror / Atom feedFrom: Hayato Kuroda (Fujitsu) <[email protected]>
To: 'Tom Lane' <[email protected]>
To: Alexander Lakhin <[email protected]>
To: Michael Paquier <[email protected]>
Cc: Aya Iwata (Fujitsu) <[email protected]>
Cc: Peter Smith <[email protected]>
Cc: Pavel Stehule <[email protected]>
Cc: Chao Li <[email protected]>
Cc: pgsql-hackers <[email protected]>
Subject: RE: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
Date: Thu, 2 Apr 2026 03:20:59 +0000
Message-ID: <OS9PR01MB12149DEAB9D2FAF32C1E8079DF551A@OS9PR01MB12149.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
<TYRPR01MB12156CA129F54361D19ECAB56F541A@TYRPR01MB12156.jpnprd01.prod.outlook.com>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Dear hackers,
Thanks for paying attention the thread.
I've been considering why the XLogFileClose() is slow only on widowbird but I
have no idea. But on this thread, I think we can just put a workaround for
stabilization.
> I don't think I want to propose a GUC for this, but could it make
> sense to check for an environment variable, similarly to PGCTLTIMEOUT
> and PG_TEST_TIMEOUT_DEFAULT? Whichever way we do it, it could replace
> the existing crude hack to change the max wait in injection-point
> mode.
I feel it might be a better approach, attached one implemented the idea.
I did not use the term "_TEST_" because such env variables are only referred
in test modules or binaries. But I did not update the documentation.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Attachments:
[application/octet-stream] 0001-Introduce-PG_BACKEND_WAIT_MAX_RETRIES.patch (5.0K, 2-0001-Introduce-PG_BACKEND_WAIT_MAX_RETRIES.patch)
download | inline diff:
From 1703fa5247615d5d8e6d223f94606e951548b72d Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <[email protected]>
Date: Thu, 2 Apr 2026 12:10:01 +0900
Subject: [PATCH] Introduce PG_BACKEND_WAIT_MAX_RETRIES
---
src/backend/storage/ipc/procarray.c | 27 +++++++++------
.../worker_spi/t/002_worker_terminate.pl | 34 +++++--------------
2 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c
index 033ae68b57e..3e6df3780fd 100644
--- a/src/backend/storage/ipc/procarray.c
+++ b/src/backend/storage/ipc/procarray.c
@@ -3777,11 +3777,12 @@ CountUserBackends(Oid roleid)
/*
* CountOtherDBBackends -- check for other backends running in the given DB
*
- * If there are other backends in the DB, we will wait a maximum of 5 seconds
- * for them to exit (or 0.3s for testing purposes). Autovacuum backends are
- * encouraged to exit early by sending them SIGTERM, but normal user backends
- * are just waited for. If background workers connected to this database are
- * marked as interruptible, they are terminated.
+ * If there are other backends in the DB, we wait up to 50 times with 100ms
+ * between attempts (5s total by default). For test purposes, the retry
+ * count can be overridden with PG_BACKEND_WAIT_MAX_RETRIES. Autovacuum
+ * backends are encouraged to exit early by sending them SIGTERM, but normal
+ * user backends are just waited for. If background workers connected to this
+ * database are marked as interruptible, they are terminated.
*
* The current backend is always ignored; it is caller's responsibility to
* check whether the current backend uses the given DB, if it's important.
@@ -3808,15 +3809,19 @@ CountOtherDBBackends(Oid databaseId, int *nbackends, int *nprepared)
int autovac_pids[MAXAUTOVACPIDS];
/*
- * Retry up to 50 times with 100ms between attempts (max 5s total). Can be
- * reduced to 3 attempts (max 0.3s total) to speed up tests.
+ * Retry up to 50 times with 100ms between attempts (max 5s total) by
+ * default. Use PG_BACKEND_WAIT_MAX_RETRIES if it's set.
*/
int ntries = 50;
+ char *env_wait;
-#ifdef USE_INJECTION_POINTS
- if (IS_INJECTION_POINT_ATTACHED("procarray-reduce-count"))
- ntries = 3;
-#endif
+ env_wait = getenv("PG_BACKEND_WAIT_MAX_RETRIES");
+ if (env_wait != NULL)
+ {
+ int val = atoi(env_wait);
+ if (val > 0)
+ ntries = val;
+ }
for (int tries = 0; tries < ntries; tries++)
{
diff --git a/src/test/modules/worker_spi/t/002_worker_terminate.pl b/src/test/modules/worker_spi/t/002_worker_terminate.pl
index b0e6a5376d4..bf9d663ca1f 100644
--- a/src/test/modules/worker_spi/t/002_worker_terminate.pl
+++ b/src/test/modules/worker_spi/t/002_worker_terminate.pl
@@ -8,13 +8,6 @@ use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
-# This test depends on injection points to detect whether background workers
-# remain.
-if ($ENV{enable_injection_points} ne 'yes')
-{
- plan skip_all => 'Injection points not supported by this build';
-}
-
# Ensure the worker_spi dynamic worker is launched on the specified database.
# Returns the PID of the worker launched.
sub launch_bgworker
@@ -70,15 +63,12 @@ autovacuum = off
debug_parallel_query = off
log_min_messages = debug1
));
-$node->start;
-# Check if the extension injection_points is available, as it may be
-# possible that this script is run with installcheck, where the module
-# would not be installed by default.
-if (!$node->check_extension('injection_points'))
-{
- plan skip_all => 'Extension injection_points not installed';
-}
+# Reduce the number of backend retries, allowing for shorter test runs. See
+# CountOtherDBBackends().
+$ENV{PG_BACKEND_WAIT_MAX_RETRIES} = 3;
+
+$node->start;
$node->safe_psql('postgres', 'CREATE EXTENSION worker_spi;');
@@ -88,12 +78,6 @@ my $pid = launch_bgworker($node, 'postgres', 0, 'false');
# Ensure CREATE DATABASE WITH TEMPLATE fails because a non-interruptible
# bgworker exists.
-# The injection point 'procarray-reduce-count' reduces the number of backend
-# retries, allowing for shorter test runs. See CountOtherDBBackends().
-$node->safe_psql('postgres', "CREATE EXTENSION injection_points;");
-$node->safe_psql('postgres',
- "SELECT injection_points_attach('procarray-reduce-count', 'error');");
-
my $stderr;
$node->psql(
@@ -119,13 +103,13 @@ $node->safe_psql(
SELECT pg_terminate_backend(pid)
FROM pg_stat_activity WHERE backend_type = 'worker_spi dynamic';));
-# The injection point is not used anymore, release it.
-$node->safe_psql('postgres',
- "SELECT injection_points_detach('procarray-reduce-count');");
-
# Check that BGWORKER_INTERRUPTIBLE allows background workers to be
# terminated with database-related commands.
+# Make the wait time longer than default to stabilize some builfarm clients
+$ENV{PG_BACKEND_WAIT_MAX_RETRIES} = 100;
+$node->restart;
+
# Test case 1: CREATE DATABASE WITH TEMPLATE
$pid = launch_bgworker($node, 'postgres', 1, 'true');
run_bgworker_interruptible_test(
--
2.47.3
view thread (67+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: RE: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE
In-Reply-To: <OS9PR01MB12149DEAB9D2FAF32C1E8079DF551A@OS9PR01MB12149.jpnprd01.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox