|
7 | 7 | use warnings;
|
8 | 8 | use PostgresNode;
|
9 | 9 | use TestLib;
|
10 |
| -use Test::More tests => 5; |
| 10 | +use Test::More tests => 16; |
11 | 11 |
|
12 | 12 | # Initialize master node
|
13 | 13 | my $node_master = get_new_node('master');
|
|
54 | 54 | is($stdout_sql, $expected, 'got expected output from SQL decoding session');
|
55 | 55 |
|
56 | 56 | my $endpos = $node_master->safe_psql('postgres', "SELECT location FROM pg_logical_slot_peek_changes('test_slot', NULL, NULL) ORDER BY location DESC LIMIT 1;");
|
57 |
| -diag "waiting to replay $endpos"; |
| 57 | +print "waiting to replay $endpos\n"; |
58 | 58 |
|
59 | 59 | my $stdout_recv = $node_master->pg_recvlogical_upto('postgres', 'test_slot', $endpos, 10, 'include-xids' => '0', 'skip-empty-xacts' => '1');
|
60 | 60 | chomp($stdout_recv);
|
|
64 | 64 | chomp($stdout_recv);
|
65 | 65 | is($stdout_recv, '', 'pg_recvlogical acknowledged changes, nothing pending on slot');
|
66 | 66 |
|
| 67 | +$node_master->safe_psql('postgres', 'CREATE DATABASE otherdb'); |
| 68 | + |
| 69 | +is($node_master->psql('otherdb', "SELECT location FROM pg_logical_slot_peek_changes('test_slot', NULL, NULL) ORDER BY location DESC LIMIT 1;"), 3, |
| 70 | + 'replaying logical slot from another database fails'); |
| 71 | + |
| 72 | +$node_master->safe_psql('otherdb', qq[SELECT pg_create_logical_replication_slot('otherdb_slot', 'test_decoding');]); |
| 73 | + |
| 74 | +# make sure you can't drop a slot while active |
| 75 | +my $pg_recvlogical = IPC::Run::start(['pg_recvlogical', '-d', $node_master->connstr('otherdb'), '-S', 'otherdb_slot', '-f', '-', '--start']); |
| 76 | +$node_master->poll_query_until('otherdb', "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NOT NULL)"); |
| 77 | +is($node_master->psql('postgres', 'DROP DATABASE otherdb'), 3, |
| 78 | + 'dropping a DB with inactive logical slots fails'); |
| 79 | +$pg_recvlogical->kill_kill; |
| 80 | +is($node_master->slot('otherdb_slot')->{'slot_name'}, undef, |
| 81 | + 'logical slot still exists'); |
| 82 | + |
| 83 | +$node_master->poll_query_until('otherdb', "SELECT EXISTS (SELECT 1 FROM pg_replication_slots WHERE slot_name = 'otherdb_slot' AND active_pid IS NULL)"); |
| 84 | +is($node_master->psql('postgres', 'DROP DATABASE otherdb'), 0, |
| 85 | + 'dropping a DB with inactive logical slots succeeds'); |
| 86 | +is($node_master->slot('otherdb_slot')->{'slot_name'}, undef, |
| 87 | + 'logical slot was actually dropped with DB'); |
| 88 | + |
| 89 | +# Restarting a node with wal_level = logical that has existing |
| 90 | +# slots must succeed, but decoding from those slots must fail. |
| 91 | +$node_master->safe_psql('postgres', 'ALTER SYSTEM SET wal_level = replica'); |
| 92 | +is($node_master->safe_psql('postgres', 'SHOW wal_level'), 'logical', 'wal_level is still logical before restart'); |
| 93 | +$node_master->restart; |
| 94 | +is($node_master->safe_psql('postgres', 'SHOW wal_level'), 'replica', 'wal_level is replica'); |
| 95 | +isnt($node_master->slot('test_slot')->{'catalog_xmin'}, '0', |
| 96 | + 'restored slot catalog_xmin is nonzero'); |
| 97 | +is($node_master->psql('postgres', qq[SELECT pg_logical_slot_get_changes('test_slot', NULL, NULL);]), 3, |
| 98 | + 'reading from slot with wal_level < logical fails'); |
| 99 | +is($node_master->psql('postgres', q[SELECT pg_drop_replication_slot('test_slot')]), 0, |
| 100 | + 'can drop logical slot while wal_level = replica'); |
| 101 | +is($node_master->slot('test_slot')->{'catalog_xmin'}, '', 'slot was dropped'); |
| 102 | + |
67 | 103 | # done with the node
|
68 | 104 | $node_master->stop;
|
0 commit comments