From b0a25a64628307df6d468c3e644672cdaf2d5687 Mon Sep 17 00:00:00 2001
From: Potapov Alexander <a.potapov@postgrespro.ru>
Date: Tue, 25 Nov 2025 07:36:29 +0300
Subject: [PATCH] Improve the test 003_start_stop.pl

Calculate the number of iterations on base of max_connections
and max_wal_senders to be in sync with backend pool size:
    2 * (max_connections + max_wal_senders)
---
 src/test/postmaster/t/003_start_stop.pl | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/test/postmaster/t/003_start_stop.pl b/src/test/postmaster/t/003_start_stop.pl
index 58e7ba6cc42..00afd7a7b90 100644
--- a/src/test/postmaster/t/003_start_stop.pl
+++ b/src/test/postmaster/t/003_start_stop.pl
@@ -48,10 +48,18 @@ if (!$node->raw_connect_works())
 
 my @raw_connections = ();
 
+my $max_connections = $node->safe_psql(
+	'postgres', qq{select setting::int max_conn from pg_settings 
+	where name=\$\$max_connections\$\$});
+my $max_wal_senders = $node->safe_psql(
+	'postgres', qq{select setting::int max_conn from pg_settings 
+	where name=\$\$max_wal_senders\$\$});
+my $backend_pool_size = 2 * ($max_connections + $max_wal_senders);
+
 # Open a lot of TCP (or Unix domain socket) connections to use up all
 # the connection slots. Beyond a certain number (roughly 2x
 # max_connections), they will be "dead-end backends".
-for (my $i = 0; $i <= 20; $i++)
+for (my $i = 0; $i < $backend_pool_size; $i++)
 {
 	my $sock = $node->raw_connect();
 
-- 
2.40.1

