Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc34677f

Browse files
committed
Fix SHOW ALL command for non-superusers with replication connection
Since Postgres 10, SHOW commands can be triggered with replicationconnections in a WAL sender context, however it missed that atransaction context is needed for syscache lookups. This commit makessure that the syscache lookups can happen correctly by setting atransaction context when running SHOW commands in a WAL sender.Superuser-only parameters can be displayed using SHOW commands not onlyto superusers, but also to members of system role pg_read_all_settings,which requires a syscache lookup to check if the connected role is amember of this system role or not, or the instance crashes. Superusersdo not need to check the syscache so it worked correctly in this case.New tests are added to cover this issue.Reported-by: Alexander KukushkinAuthor: Michael PaquierReviewed-by: Álvaro HerreraDiscussion:https://postgr.es/m/15734-2daa8761eeed8e20@postgresql.orgBackpatch-through: 10
1 parent4ab02e8 commitc34677f

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

‎src/backend/replication/walsender.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,10 @@ exec_replication_command(const char *cmd_string)
15521552
DestReceiver*dest=CreateDestReceiver(DestRemoteSimple);
15531553
VariableShowStmt*n= (VariableShowStmt*)cmd_node;
15541554

1555+
/* syscache access needs a transaction environment */
1556+
StartTransactionCommand();
15551557
GetPGVariable(n->name,dest);
1558+
CommitTransactionCommand();
15561559
}
15571560
break;
15581561

‎src/test/recovery/t/001_stream_rep.pl

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
use warnings;
44
use PostgresNode;
55
use TestLib;
6-
use Test::Moretests=>26;
6+
use Test::Moretests=>32;
77

88
# Initialize master node
99
my$node_master = get_new_node('master');
10-
$node_master->init(allows_streaming=> 1);
10+
# A specific role is created to perform some tests related to replication,
11+
# and it needs proper authentication configuration.
12+
$node_master->init(allows_streaming=> 1,
13+
auth_extra=> ['--create-role','repl_role']);
1114
$node_master->start;
1215
my$backup_name ='my_backup';
1316

@@ -117,6 +120,55 @@ sub test_target_session_attrs
117120
test_target_session_attrs($node_standby_1,$node_master,$node_standby_1,
118121
"any", 0);
119122

123+
# Test for SHOW commands using a WAL sender connection with a replication
124+
# role.
125+
note"testing SHOW commands for replication connection";
126+
127+
$node_master->psql('postgres',"
128+
CREATE ROLE repl_role REPLICATION LOGIN;
129+
GRANT pg_read_all_settings TO repl_role;");
130+
my$master_host =$node_master->host;
131+
my$master_port =$node_master->port;
132+
my$connstr_common ="host=$master_host port=$master_port user=repl_role";
133+
my$connstr_rep ="$connstr_common replication=1";
134+
my$connstr_db ="$connstr_common replication=database dbname=postgres";
135+
136+
# Test SHOW ALL
137+
my ($ret,$stdout,$stderr) =
138+
$node_master->psql('postgres','SHOW ALL;',
139+
on_error_die=> 1,
140+
extra_params=> ['-d',$connstr_rep ]);
141+
ok($ret == 0,"SHOW ALL with replication role and physical replication");
142+
($ret,$stdout,$stderr) =
143+
$node_master->psql('postgres','SHOW ALL;',
144+
on_error_die=> 1,
145+
extra_params=> ['-d',$connstr_db ]);
146+
ok($ret == 0,"SHOW ALL with replication role and logical replication");
147+
148+
# Test SHOW with a user-settable parameter
149+
($ret,$stdout,$stderr) =
150+
$node_master->psql('postgres','SHOW work_mem;',
151+
on_error_die=> 1,
152+
extra_params=> ['-d',$connstr_rep ]);
153+
ok($ret == 0,"SHOW with user-settable parameter, replication role and physical replication");
154+
($ret,$stdout,$stderr) =
155+
$node_master->psql('postgres','SHOW work_mem;',
156+
on_error_die=> 1,
157+
extra_params=> ['-d',$connstr_db ]);
158+
ok($ret == 0,"SHOW with user-settable parameter, replication role and logical replication");
159+
160+
# Test SHOW with a superuser-settable parameter
161+
($ret,$stdout,$stderr) =
162+
$node_master->psql('postgres','SHOW primary_conninfo;',
163+
on_error_die=> 1,
164+
extra_params=> ['-d',$connstr_rep ]);
165+
ok($ret == 0,"SHOW with superuser-settable parameter, replication role and physical replication");
166+
($ret,$stdout,$stderr) =
167+
$node_master->psql('postgres','SHOW primary_conninfo;',
168+
on_error_die=> 1,
169+
extra_params=> ['-d',$connstr_db ]);
170+
ok($ret == 0,"SHOW with superuser-settable parameter, replication role and logical replication");
171+
120172
note"switching to physical replication slot";
121173

122174
# Switch to using a physical replication slot. We can do this without a new

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp