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

Commita81e551

Browse files
author
Amit Kapila
committed
Fix the ALTER SUBSCRIPTION to reflect the change in run_as_owner option.
Reported-by: Jeff DavisAuthor: Hou ZhijieReviewed-by: Amit KapilaBackpatch-through: 16Discussion:http://postgr.es/m/17b62714fd115bd1899afd922954540a5c6a0467.camel@j-davis.com
1 parentf899c7f commita81e551

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

‎src/backend/commands/subscriptioncmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,13 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
12041204
= true;
12051205
}
12061206

1207+
if (IsSet(opts.specified_opts,SUBOPT_RUN_AS_OWNER))
1208+
{
1209+
values[Anum_pg_subscription_subrunasowner-1]=
1210+
BoolGetDatum(opts.runasowner);
1211+
replaces[Anum_pg_subscription_subrunasowner-1]= true;
1212+
}
1213+
12071214
if (IsSet(opts.specified_opts,SUBOPT_ORIGIN))
12081215
{
12091216
values[Anum_pg_subscription_suborigin-1]=

‎src/test/regress/expected/subscription.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,16 @@ ALTER SUBSCRIPTION regress_testsub SET PUBLICATION testpub2, testpub3 WITH (refr
155155
ALTER SUBSCRIPTION regress_testsub CONNECTION 'dbname=regress_doesnotexist2';
156156
ALTER SUBSCRIPTION regress_testsub SET (slot_name = 'newname');
157157
ALTER SUBSCRIPTION regress_testsub SET (password_required = false);
158+
ALTER SUBSCRIPTION regress_testsub SET (run_as_owner = true);
158159
\dRs+
159160
List of subscriptions
160161
Name | Owner | Enabled | Publication | Binary | Streaming | Two-phase commit | Disable on error | Origin | Password required | Run as owner? | Synchronous commit | Conninfo | Skip LSN
161162
-----------------+---------------------------+---------+---------------------+--------+-----------+------------------+------------------+--------+-------------------+---------------+--------------------+------------------------------+----------
162-
regress_testsub | regress_subscription_user | f | {testpub2,testpub3} | f | off | d | f | any | f |f | off | dbname=regress_doesnotexist2 | 0/0
163+
regress_testsub | regress_subscription_user | f | {testpub2,testpub3} | f | off | d | f | any | f |t | off | dbname=regress_doesnotexist2 | 0/0
163164
(1 row)
164165

165166
ALTER SUBSCRIPTION regress_testsub SET (password_required = true);
167+
ALTER SUBSCRIPTION regress_testsub SET (run_as_owner = false);
166168
-- fail
167169
ALTER SUBSCRIPTION regress_testsub SET (slot_name = '');
168170
ERROR: replication slot name "" is too short

‎src/test/regress/sql/subscription.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ ALTER SUBSCRIPTION regress_testsub SET PUBLICATION testpub2, testpub3 WITH (refr
9494
ALTER SUBSCRIPTION regress_testsub CONNECTION'dbname=regress_doesnotexist2';
9595
ALTER SUBSCRIPTION regress_testsubSET (slot_name='newname');
9696
ALTER SUBSCRIPTION regress_testsubSET (password_required= false);
97+
ALTER SUBSCRIPTION regress_testsubSET (run_as_owner= true);
9798
\dRs+
9899

99100
ALTER SUBSCRIPTION regress_testsubSET (password_required= true);
101+
ALTER SUBSCRIPTION regress_testsubSET (run_as_owner= false);
100102

101103
-- fail
102104
ALTER SUBSCRIPTION regress_testsubSET (slot_name='');

‎src/test/subscription/t/033_run_as_table_owner.pl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,37 @@ sub revoke_superuser
193193
expect_replication("alice.unpartitioned", 3, 7, 13,
194194
"with INHERIT but not SET ROLE can replicate");
195195

196+
# Similar to the previous test, remove all privileges again and instead,
197+
# give the ability to SET ROLE to regress_alice.
198+
$node_subscriber->safe_psql(
199+
'postgres',qq(
200+
SET SESSION AUTHORIZATION regress_alice;
201+
REVOKE ALL PRIVILEGES ON alice.unpartitioned FROM regress_admin;
202+
RESET SESSION AUTHORIZATION;
203+
GRANT regress_alice TO regress_admin WITH INHERIT FALSE, SET TRUE;
204+
));
205+
206+
# Because replication is running as the subscription owner in this test,
207+
# the above grant doesn't help.
208+
publish_insert("alice.unpartitioned", 14);
209+
expect_failure(
210+
"alice.unpartitioned",
211+
3,
212+
7,
213+
13,
214+
qr/ERROR: ( [A-Z0-9]+:)? permission denied for table unpartitioned/msi,
215+
"with no privileges cannot replicate");
216+
217+
# Allow the replication to run as table owner and check that things start
218+
# working.
219+
$node_subscriber->safe_psql(
220+
'postgres',qq(
221+
ALTER SUBSCRIPTION admin_sub SET (run_as_owner = false);
222+
));
223+
224+
expect_replication("alice.unpartitioned", 4, 7, 14,
225+
"can replicate after setting run_as_owner to false");
226+
196227
# Remove the subscrition and truncate the table for the initial data sync
197228
# tests.
198229
$node_subscriber->safe_psql(
@@ -222,7 +253,7 @@ sub revoke_superuser
222253
# Because the initial data sync is working as the table owner, all
223254
# data should be copied.
224255
$node_subscriber->wait_for_subscription_sync($node_publisher,'admin_sub');
225-
expect_replication("alice.unpartitioned",3, 7,13,
256+
expect_replication("alice.unpartitioned",4, 7,14,
226257
"table owner can do the initial data copy");
227258

228259
done_testing();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp