|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use PostgreSQL::Test::Cluster; |
| 4 | +use PostgreSQL::Test::Utils; |
| 5 | +use Test::More; |
| 6 | + |
| 7 | +# Tests the slot manipulation in the single-user mode |
| 8 | + |
| 9 | +# Skip the whole thing on the windows platform |
| 10 | +if ($windows_os) |
| 11 | +{ |
| 12 | + plan skip_all => 'this test is not supported by this platform'; |
| 13 | +} |
| 14 | + |
| 15 | +# Run passed commands in single-user mode. The return value from the command is |
| 16 | +# passed through. |
| 17 | +sub run_test_in_single_user_mode |
| 18 | +{ |
| 19 | + my ($node, $commands, $testname) = @_; |
| 20 | + |
| 21 | + my $result = run_log( |
| 22 | + [ |
| 23 | + 'postgres', '--single', '-F', |
| 24 | + '-c' => 'exit_on_error=true', |
| 25 | + '-D' => $node->data_dir, |
| 26 | + 'postgres' |
| 27 | + ], |
| 28 | + \$commands); |
| 29 | + |
| 30 | + ok($result, $testname); |
| 31 | +} |
| 32 | + |
| 33 | +my $slotname = 'test_slot'; |
| 34 | + |
| 35 | +# Initialize a node |
| 36 | +my $node = PostgreSQL::Test::Cluster->new('node'); |
| 37 | +$node->init(allows_streaming => "logical"); |
| 38 | +$node->start; |
| 39 | + |
| 40 | +# Define initial table |
| 41 | +$node->safe_psql('postgres', "CREATE TABLE foo (id int)"); |
| 42 | + |
| 43 | +# Stop the node to run and test in single-user mode |
| 44 | +$node->stop; |
| 45 | + |
| 46 | +run_test_in_single_user_mode( |
| 47 | + $node, |
| 48 | + "SELECT pg_create_logical_replication_slot('$slotname', 'test_decoding')", |
| 49 | + "replication slot can be created in single-user mode"); |
| 50 | + |
| 51 | +run_test_in_single_user_mode( |
| 52 | + $node, qq( |
| 53 | +INSERT INTO foo VALUES (1); |
| 54 | +SELECT count(1) FROM pg_logical_slot_get_changes('$slotname', NULL, NULL); |
| 55 | +), |
| 56 | + "logical decoding be done in single-user mode"); |
| 57 | + |
| 58 | +run_test_in_single_user_mode( |
| 59 | + $node, |
| 60 | + "SELECT pg_replication_slot_advance('$slotname', pg_current_wal_lsn())", |
| 61 | + "replication slot can be advanced in single-user mode"); |
| 62 | + |
| 63 | +run_test_in_single_user_mode( |
| 64 | + $node, |
| 65 | + "SELECT pg_copy_logical_replication_slot('$slotname', 'dest_slot')", |
| 66 | + "replication slot can be copied in single-user mode"); |
| 67 | + |
| 68 | +run_test_in_single_user_mode( |
| 69 | + $node, |
| 70 | + "SELECT pg_drop_replication_slot('$slotname')", |
| 71 | + "replication slot can be dropped in single-user mode"); |
| 72 | + |
| 73 | +done_testing(); |
0 commit comments