|
104 | 104 | 'dynamic bgworkers all launched'
|
105 | 105 | ) or die "Timed out while waiting for dynamic bgworkers to be launched";
|
106 | 106 |
|
| 107 | +# Check BGWORKER_BYPASS_ALLOWCONN. |
| 108 | +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS false;)); |
| 109 | +my $log_offset = -s $node->logfile; |
| 110 | + |
| 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 | +$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'); |
| 120 | + |
| 121 | +# bgworker bypasses the connection check, and can be launched. |
| 122 | +my $worker4_pid = $node->safe_psql('postgres', |
| 123 | + qq[SELECT worker_spi_launch(12, $mydb_id, $myrole_id, '{"ALLOWCONN"}');]); |
| 124 | +ok( $node->poll_query_until( |
| 125 | + 'postgres', |
| 126 | + qq[SELECT datname, usename, wait_event FROM pg_stat_activity |
| 127 | + WHERE backend_type = 'worker_spi dynamic' AND |
| 128 | + pid IN ($worker4_pid) ORDER BY datname;], |
| 129 | + qq[mydb|myrole|WorkerSpiMain]), |
| 130 | + 'dynamic bgworker with BYPASS_ALLOWCONN started'); |
| 131 | + |
| 132 | +$node->safe_psql('postgres', q(ALTER DATABASE mydb ALLOW_CONNECTIONS true;)); |
| 133 | + |
107 | 134 | done_testing();
|
0 commit comments