|
105 | 105 | ) or die "Timed out while waiting for dynamic bgworkers to be launched";
|
106 | 106 |
|
107 | 107 | # Check BGWORKER_BYPASS_ALLOWCONN.
|
108 |
| -$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false;)); |
| 108 | +$node->safe_psql('postgres', |
| 109 | + q(CREATE DATABASE noconndb ALLOW_CONNECTIONS false;)); |
| 110 | +my $noconndb_id = $node->safe_psql('mydb', |
| 111 | + "SELECT oid FROM pg_database where datname = 'noconndb';"); |
109 | 112 | my $log_offset = -s $node->logfile;
|
110 | 113 |
|
111 |
| -# bgworker cannot be launched with connection restriction. |
112 |
| -my $worker3_pid = $node->safe_psql('postgres', |
113 |
| - qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id);]); |
| 114 | +# worker_spi_launch() may be able to detect that the worker has been |
| 115 | +# stopped, so do not rely on psql_safe(). |
| 116 | +$node->psql('postgres', |
| 117 | + qq[SELECT worker_spi_launch(12, $noconndb_id, $myrole_id);]); |
114 | 118 | $node->wait_for_log(
|
115 |
| - qr/database "mydb" is not currently accepting connections/, $log_offset); |
116 |
| - |
117 |
| -$result = $node->safe_psql('postgres', |
118 |
| - "SELECT count(*) FROM pg_stat_activity WHERE pid = $worker3_pid;"); |
119 |
| -is($result, '0', 'dynamic bgworker without BYPASS_ALLOWCONN not started'); |
| 119 | + qr/database "noconndb" is not currently accepting connections/, |
| 120 | + $log_offset); |
120 | 121 |
|
121 | 122 | # bgworker bypasses the connection check, and can be launched.
|
122 | 123 | my $worker4_pid = $node->safe_psql('postgres',
|
123 |
| - qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]); |
| 124 | + qq[SELECT worker_spi_launch(12, $noconndb_id, $myrole_id, '{"ALLOWCONN"}');] |
| 125 | +); |
124 | 126 | ok( $node->poll_query_until(
|
125 | 127 | 'postgres',
|
126 | 128 | qq[SELECT datname, usename, wait_event FROM pg_stat_activity
|
127 | 129 | WHERE backend_type = 'worker_spi dynamic' AND
|
128 | 130 | pid IN ($worker4_pid) ORDER BY datname;],
|
129 |
| - qq[mydb|myrole|WorkerSpiMain]), |
| 131 | + qq[noconndb|myrole|WorkerSpiMain]), |
130 | 132 | 'dynamic bgworker with BYPASS_ALLOWCONN started');
|
131 | 133 |
|
132 |
| -$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;)); |
133 |
| - |
134 | 134 | done_testing();
|
0 commit comments