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

Commit9907b55

Browse files
committed
Fix ALTER SUBSCRIPTION grammar ambiguity
There was a grammar ambiguity between SET PUBLICATION name REFRESH andSET PUBLICATION SKIP REFRESH, because SKIP is not a reserved word. Toresolve that, fold the refresh choice into the WITH options. Refreshingis the default now.Reported-by: tushar <tushar.ahuja@enterprisedb.com>
1 parent06bfb80 commit9907b55

File tree

8 files changed

+54
-38
lines changed

8 files changed

+54
-38
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6609,7 +6609,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</>:<replaceable>&lt;salt&gt;<
66096609
<para>
66106610
This catalog only contains tables known to the subscription after running
66116611
either <command>CREATE SUBSCRIPTION</command> or
6612-
<command>ALTER SUBSCRIPTION ... REFRESH</command>.
6612+
<command>ALTER SUBSCRIPTION ... REFRESH PUBLICATION</command>.
66136613
</para>
66146614

66156615
<table>

‎doc/src/sgml/ref/alter_subscription.sgml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> CONNECTION '<replaceable>conninfo</replaceable>'
25-
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> SET PUBLICATION <replaceable class="PARAMETER">publication_name</replaceable> [, ...]{ REFRESH[ WITH ( <replaceable class="PARAMETER">refresh_option</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) ] | SKIP REFRESH }
25+
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> SET PUBLICATION <replaceable class="PARAMETER">publication_name</replaceable> [, ...] [ WITH ( <replaceable class="PARAMETER">set_publication_option</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) ]
2626
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> REFRESH PUBLICATION [ WITH ( <replaceable class="PARAMETER">refresh_option</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) ]
2727
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> ENABLE
2828
ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> DISABLE
@@ -80,18 +80,29 @@ ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> RENAME TO <
8080
<para>
8181
Changes list of subscribed publications. See
8282
<xref linkend="SQL-CREATESUBSCRIPTION"> for more information.
83+
By default this command will also act like <literal>REFRESH
84+
PUBLICATION</literal>.
8385
</para>
8486

8587
<para>
86-
When <literal>REFRESH</literal> is specified, this command will also act
87-
like <literal>REFRESH
88-
PUBLICATION</literal>. <literal>refresh_option</literal> specifies
89-
additional options for the refresh operation, as described
90-
under <literal>REFRESH PUBLICATION</literal>. When
91-
<literal>SKIP REFRESH</literal> is specified, the command will not try
92-
to refresh table information. Note that
93-
either <literal>REFRESH</literal> or <literal>SKIP REFRESH</literal>
94-
must be specified.
88+
<replaceable>set_publication_option</replaceable> specifies additional
89+
options for this operation. The supported options are:
90+
91+
<variablelist>
92+
<varlistentry>
93+
<term><literal>refresh</literal> (<type>boolean</type>)</term>
94+
<listitem>
95+
<para>
96+
When false, the command will not try to refresh table information.
97+
<literal>REFRESH PUBLICATION</literal> should then be executed separately.
98+
The default is <literal>true</literal>.
99+
</para>
100+
</listitem>
101+
</varlistentry>
102+
</variablelist>
103+
104+
Additionally, refresh options as described
105+
under <literal>REFRESH PUBLICATION</literal> may be specified.
95106
</para>
96107
</listitem>
97108
</varlistentry>
@@ -107,7 +118,7 @@ ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> RENAME TO <
107118
</para>
108119

109120
<para>
110-
<literal>refresh_option</literal> specifies additional options for the
121+
<replaceable>refresh_option</replaceable> specifies additional options for the
111122
refresh operation. The supported options are:
112123

113124
<variablelist>
@@ -185,7 +196,7 @@ ALTER SUBSCRIPTION <replaceable class="PARAMETER">name</replaceable> RENAME TO <
185196
Change the publication subscribed by a subscription to
186197
<literal>insert_only</literal>:
187198
<programlisting>
188-
ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only REFRESH;
199+
ALTER SUBSCRIPTION mysub SET PUBLICATION insert_only;
189200
</programlisting>
190201
</para>
191202

‎src/backend/commands/subscriptioncmds.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ static void
6464
parse_subscription_options(List*options,bool*connect,bool*enabled_given,
6565
bool*enabled,bool*create_slot,
6666
bool*slot_name_given,char**slot_name,
67-
bool*copy_data,char**synchronous_commit)
67+
bool*copy_data,char**synchronous_commit,
68+
bool*refresh)
6869
{
6970
ListCell*lc;
7071
boolconnect_given= false;
7172
boolcreate_slot_given= false;
7273
boolcopy_data_given= false;
74+
boolrefresh_given= false;
7375

7476
/* If connect is specified, the others also need to be. */
7577
Assert(!connect|| (enabled&&create_slot&&copy_data));
@@ -92,6 +94,8 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given,
9294
*copy_data= true;
9395
if (synchronous_commit)
9496
*synchronous_commit=NULL;
97+
if (refresh)
98+
*refresh= true;
9599

96100
/* Parse options */
97101
foreach(lc,options)
@@ -167,6 +171,16 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given,
167171
PGC_BACKEND,PGC_S_TEST,GUC_ACTION_SET,
168172
false,0, false);
169173
}
174+
elseif (strcmp(defel->defname,"refresh")==0&&refresh)
175+
{
176+
if (refresh_given)
177+
ereport(ERROR,
178+
(errcode(ERRCODE_SYNTAX_ERROR),
179+
errmsg("conflicting or redundant options")));
180+
181+
refresh_given= true;
182+
*refresh=defGetBoolean(defel);
183+
}
170184
else
171185
ereport(ERROR,
172186
(errcode(ERRCODE_SYNTAX_ERROR),
@@ -315,7 +329,8 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
315329
*/
316330
parse_subscription_options(stmt->options,&connect,&enabled_given,
317331
&enabled,&create_slot,&slotname_given,
318-
&slotname,&copy_data,&synchronous_commit);
332+
&slotname,&copy_data,&synchronous_commit,
333+
NULL);
319334

320335
/*
321336
* Since creating a replication slot is not transactional, rolling back
@@ -645,7 +660,7 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
645660

646661
parse_subscription_options(stmt->options,NULL,NULL,NULL,
647662
NULL,&slotname_given,&slotname,
648-
NULL,&synchronous_commit);
663+
NULL,&synchronous_commit,NULL);
649664

650665
if (slotname_given)
651666
{
@@ -680,7 +695,7 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
680695

681696
parse_subscription_options(stmt->options,NULL,
682697
&enabled_given,&enabled,NULL,
683-
NULL,NULL,NULL,NULL);
698+
NULL,NULL,NULL,NULL,NULL);
684699
Assert(enabled_given);
685700

686701
if (!sub->slotname&&enabled)
@@ -712,13 +727,13 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
712727
break;
713728

714729
caseALTER_SUBSCRIPTION_PUBLICATION:
715-
caseALTER_SUBSCRIPTION_PUBLICATION_REFRESH:
716730
{
717731
boolcopy_data;
732+
boolrefresh;
718733

719734
parse_subscription_options(stmt->options,NULL,NULL,NULL,
720735
NULL,NULL,NULL,&copy_data,
721-
NULL);
736+
NULL,&refresh);
722737

723738
values[Anum_pg_subscription_subpublications-1]=
724739
publicationListToArray(stmt->publication);
@@ -727,12 +742,13 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
727742
update_tuple= true;
728743

729744
/* Refresh if user asked us to. */
730-
if (stmt->kind==ALTER_SUBSCRIPTION_PUBLICATION_REFRESH)
745+
if (refresh)
731746
{
732747
if (!sub->enabled)
733748
ereport(ERROR,
734749
(errcode(ERRCODE_SYNTAX_ERROR),
735-
errmsg("ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions")));
750+
errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
751+
errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
736752

737753
/* Make sure refresh sees the new list of publications. */
738754
sub->publications=stmt->publication;
@@ -754,7 +770,7 @@ AlterSubscription(AlterSubscriptionStmt *stmt)
754770

755771
parse_subscription_options(stmt->options,NULL,NULL,NULL,
756772
NULL,NULL,NULL,&copy_data,
757-
NULL);
773+
NULL,NULL);
758774

759775
AlterSubscription_refresh(sub,copy_data);
760776

‎src/backend/parser/gram.y

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9279,24 +9279,14 @@ AlterSubscriptionStmt:
92799279
n->options =$6;
92809280
$$ = (Node *)n;
92819281
}
9282-
|ALTERSUBSCRIPTIONnameSETPUBLICATIONpublication_name_listREFRESHopt_definition
9283-
{
9284-
AlterSubscriptionStmt *n =
9285-
makeNode(AlterSubscriptionStmt);
9286-
n->kind = ALTER_SUBSCRIPTION_PUBLICATION_REFRESH;
9287-
n->subname =$3;
9288-
n->publication =$6;
9289-
n->options =$8;
9290-
$$ = (Node *)n;
9291-
}
9292-
|ALTERSUBSCRIPTIONnameSETPUBLICATIONpublication_name_listSKIPREFRESH
9282+
|ALTERSUBSCRIPTIONnameSETPUBLICATIONpublication_name_listopt_definition
92939283
{
92949284
AlterSubscriptionStmt *n =
92959285
makeNode(AlterSubscriptionStmt);
92969286
n->kind = ALTER_SUBSCRIPTION_PUBLICATION;
92979287
n->subname =$3;
92989288
n->publication =$6;
9299-
n->options =NIL;
9289+
n->options =$7;
93009290
$$ = (Node *)n;
93019291
}
93029292
|ALTERSUBSCRIPTIONnameENABLE_P

‎src/include/nodes/parsenodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,6 @@ typedef enum AlterSubscriptionType
33823382
ALTER_SUBSCRIPTION_OPTIONS,
33833383
ALTER_SUBSCRIPTION_CONNECTION,
33843384
ALTER_SUBSCRIPTION_PUBLICATION,
3385-
ALTER_SUBSCRIPTION_PUBLICATION_REFRESH,
33863385
ALTER_SUBSCRIPTION_REFRESH,
33873386
ALTER_SUBSCRIPTION_ENABLED
33883387
}AlterSubscriptionType;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ ERROR: invalid connection string syntax: missing "=" after "foobar" in connecti
8282
testsub | regress_subscription_user | f | {testpub} | off | dbname=doesnotexist
8383
(1 row)
8484

85-
ALTER SUBSCRIPTION testsub SET PUBLICATION testpub2, testpub3SKIP REFRESH;
85+
ALTER SUBSCRIPTION testsub SET PUBLICATION testpub2, testpub3WITH (refresh = false);
8686
ALTER SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist2';
8787
ALTER SUBSCRIPTION testsub SET (slot_name = 'newname');
8888
-- fail

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ ALTER SUBSCRIPTION testsub CONNECTION 'foobar';
6161

6262
\dRs+
6363

64-
ALTER SUBSCRIPTION testsubSET PUBLICATION testpub2, testpub3SKIP REFRESH;
64+
ALTER SUBSCRIPTION testsubSET PUBLICATION testpub2, testpub3WITH (refresh= false);
6565
ALTER SUBSCRIPTION testsub CONNECTION'dbname=doesnotexist2';
6666
ALTER SUBSCRIPTION testsubSET (slot_name='newname');
6767

‎src/test/subscription/t/001_rep_changes.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"SELECT pid FROM pg_stat_replication WHERE application_name = '$appname';"
144144
);
145145
$node_subscriber->safe_psql('postgres',
146-
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_onlyREFRESHWITH (copy_data = false)"
146+
"ALTER SUBSCRIPTION tap_sub SET PUBLICATION tap_pub_ins_only WITH (copy_data = false)"
147147
);
148148
$node_publisher->poll_query_until('postgres',
149149
"SELECT pid !=$oldpid FROM pg_stat_replication WHERE application_name = '$appname';"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp