|
| 1 | +# Copyright (c) 2025, PostgreSQL Global Development Group |
| 2 | + |
| 3 | +# Test manipulations of replication slots with the single-user mode. |
| 4 | + |
| 5 | +use strict; |
| 6 | +use warnings; |
| 7 | +use PostgreSQL::Test::Cluster; |
| 8 | +use PostgreSQL::Test::Utils; |
| 9 | +use Test::More; |
| 10 | + |
| 11 | +# Skip the tests on Windows, as single-user mode would fail on permission |
| 12 | +# failure with privileged accounts. |
| 13 | +if ($windows_os) |
| 14 | +{ |
| 15 | + plan skip_all => 'this test is not supported by this platform'; |
| 16 | +} |
| 17 | + |
| 18 | +# Run set of queries in single-user mode. |
| 19 | +sub test_single_mode |
| 20 | +{ |
| 21 | + my ($node, $queries, $testname) = @_; |
| 22 | + |
| 23 | + my $result = run_log( |
| 24 | + [ |
| 25 | + 'postgres', '--single', '-F', |
| 26 | + '-c' => 'exit_on_error=true', |
| 27 | + '-D' => $node->data_dir, |
| 28 | + 'postgres' |
| 29 | + ], |
| 30 | + '<' => \$queries); |
| 31 | + |
| 32 | + ok($result, $testname); |
| 33 | +} |
| 34 | + |
| 35 | +my $slot_logical = 'slot_logical'; |
| 36 | +my $slot_physical = 'slot_physical'; |
| 37 | + |
| 38 | +# Initialize a node |
| 39 | +my $node = PostgreSQL::Test::Cluster->new('node'); |
| 40 | +$node->init(allows_streaming => "logical"); |
| 41 | +$node->start; |
| 42 | + |
| 43 | +# Define initial table |
| 44 | +$node->safe_psql('postgres', "CREATE TABLE foo (id int)"); |
| 45 | + |
| 46 | +$node->stop; |
| 47 | + |
| 48 | +test_single_mode( |
| 49 | + $node, |
| 50 | + "SELECT pg_create_logical_replication_slot('$slot_logical', 'test_decoding')", |
| 51 | + "logical slot creation"); |
| 52 | +test_single_mode( |
| 53 | + $node, |
| 54 | + "SELECT pg_create_physical_replication_slot('$slot_physical', true)", |
| 55 | + "physical slot creation"); |
| 56 | +test_single_mode( |
| 57 | + $node, |
| 58 | + "SELECT pg_create_physical_replication_slot('slot_tmp', true, true)", |
| 59 | + "temporary physical slot creation"); |
| 60 | + |
| 61 | +test_single_mode( |
| 62 | + $node, qq( |
| 63 | +INSERT INTO foo VALUES (1); |
| 64 | +SELECT pg_logical_slot_get_changes('$slot_logical', NULL, NULL); |
| 65 | +), |
| 66 | + "logical decoding"); |
| 67 | + |
| 68 | +test_single_mode( |
| 69 | + $node, |
| 70 | + "SELECT pg_replication_slot_advance('$slot_logical', pg_current_wal_lsn())", |
| 71 | + "logical slot advance"); |
| 72 | +test_single_mode( |
| 73 | + $node, |
| 74 | + "SELECT pg_replication_slot_advance('$slot_physical', pg_current_wal_lsn())", |
| 75 | + "physical slot advance"); |
| 76 | + |
| 77 | +test_single_mode( |
| 78 | + $node, |
| 79 | + "SELECT pg_copy_logical_replication_slot('$slot_logical', 'slot_log_copy')", |
| 80 | + "logical slot copy"); |
| 81 | +test_single_mode( |
| 82 | + $node, |
| 83 | + "SELECT pg_copy_physical_replication_slot('$slot_physical', 'slot_phy_copy')", |
| 84 | + "physical slot copy"); |
| 85 | + |
| 86 | +test_single_mode( |
| 87 | + $node, |
| 88 | + "SELECT pg_drop_replication_slot('$slot_logical')", |
| 89 | + "logical slot drop"); |
| 90 | +test_single_mode( |
| 91 | + $node, |
| 92 | + "SELECT pg_drop_replication_slot('$slot_physical')", |
| 93 | + "physical slot drop"); |
| 94 | + |
| 95 | +done_testing(); |
0 commit comments