Skip to content

Commit b21aa3b

Browse files
HUUTFJCommitfest Bot
authored andcommitted
Set ReplicationSlot::active_pid even in single-user mode
Slot manipulation functions except drop could be failed in single-user mode, because active_pid was not set. Actually the attribute is no-op in the mode but fix the inconsisntency anyway.
1 parent 38c5fbd commit b21aa3b

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

src/backend/replication/slot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ ReplicationSlotAcquire(const char *name, bool nowait, bool error_if_invalid)
653653
}
654654
else
655655
{
656-
active_pid = MyProcPid;
656+
s->active_pid = active_pid = MyProcPid;
657657
ReplicationSlotSetInactiveSince(s, 0, true);
658658
}
659659
LWLockRelease(ReplicationSlotControlLock);

src/test/modules/test_misc/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tests += {
1616
't/005_timeouts.pl',
1717
't/006_signal_autovacuum.pl',
1818
't/007_catcache_inval.pl',
19+
't/008_slots_in_single_user_mode.pl',
1920
],
2021
},
2122
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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();

src/test/recovery/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ tests += {
5656
't/045_archive_restartpoint.pl',
5757
't/046_checkpoint_logical_slot.pl',
5858
't/047_checkpoint_physical_slot.pl',
59-
't/048_vacuum_horizon_floor.pl'
59+
't/048_vacuum_horizon_floor.pl',
6060
],
6161
},
6262
}

0 commit comments

Comments
 (0)