Skip to content

Commit 915a6c4

Browse files
committed
Improve errhint for ALTER SUBSCRIPTION ADD/DROP PUBLICATION
The original hint says to use SET PUBLICATION when really ADD/DROP PUBLICATION is called for, so this is arguably a bug fix. Also, a very similar message elsewhere was using an inconsistent SQLSTATE. While at it, unwrap some strings. Backpatch to 15. Author: Hou zj <houzj.fnst@fujitsu.com> Discussion: https://postgr.es/m/OS0PR01MB57160AD0E7386547BA978EB394299@OS0PR01MB5716.jpnprd01.prod.outlook.com
1 parent eddc128 commit 915a6c4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/backend/commands/subscriptioncmds.c

+16-11
Original file line numberDiff line numberDiff line change
@@ -1182,10 +1182,9 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
11821182
*/
11831183
if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_ENABLED && opts.copy_data)
11841184
ereport(ERROR,
1185-
(errcode(ERRCODE_SYNTAX_ERROR),
1185+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
11861186
errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
1187-
errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION with refresh = false, or with copy_data = false"
1188-
", or use DROP/CREATE SUBSCRIPTION.")));
1187+
errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION with refresh = false, or with copy_data = false, or use DROP/CREATE SUBSCRIPTION.")));
11891188

11901189
PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
11911190

@@ -1226,18 +1225,25 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
12261225
ereport(ERROR,
12271226
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12281227
errmsg("ALTER SUBSCRIPTION with refresh is not allowed for disabled subscriptions"),
1229-
errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).")));
1228+
/* translator: %s is an SQL ALTER command */
1229+
errhint("Use %s instead.",
1230+
isadd ?
1231+
"ALTER SUBSCRIPTION ... ADD PUBLICATION ... WITH (refresh = false)" :
1232+
"ALTER SUBSCRIPTION ... DROP PUBLICATION ... WITH (refresh = false)")));
12301233

12311234
/*
12321235
* See ALTER_SUBSCRIPTION_REFRESH for details why this is
12331236
* not allowed.
12341237
*/
12351238
if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_ENABLED && opts.copy_data)
12361239
ereport(ERROR,
1237-
(errcode(ERRCODE_SYNTAX_ERROR),
1240+
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
12381241
errmsg("ALTER SUBSCRIPTION with refresh and copy_data is not allowed when two_phase is enabled"),
1239-
errhint("Use ALTER SUBSCRIPTION ... SET PUBLICATION with refresh = false, or with copy_data = false"
1240-
", or use DROP/CREATE SUBSCRIPTION.")));
1242+
/* translator: %s is an SQL ALTER command */
1243+
errhint("Use %s with refresh = false, or with copy_data = false, or use DROP/CREATE SUBSCRIPTION.",
1244+
isadd ?
1245+
"ALTER SUBSCRIPTION ... ADD PUBLICATION" :
1246+
"ALTER SUBSCRIPTION ... DROP PUBLICATION")));
12411247

12421248
PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION with refresh");
12431249

@@ -1282,8 +1288,7 @@ AlterSubscription(ParseState *pstate, AlterSubscriptionStmt *stmt,
12821288
ereport(ERROR,
12831289
(errcode(ERRCODE_SYNTAX_ERROR),
12841290
errmsg("ALTER SUBSCRIPTION ... REFRESH with copy_data is not allowed when two_phase is enabled"),
1285-
errhint("Use ALTER SUBSCRIPTION ... REFRESH with copy_data = false"
1286-
", or use DROP/CREATE SUBSCRIPTION.")));
1291+
errhint("Use ALTER SUBSCRIPTION ... REFRESH with copy_data = false, or use DROP/CREATE SUBSCRIPTION.")));
12871292

12881293
PreventInTransactionBlock(isTopLevel, "ALTER SUBSCRIPTION ... REFRESH");
12891294

@@ -2011,8 +2016,8 @@ ReportSlotConnectionError(List *rstates, Oid subid, char *slotname, char *err)
20112016

20122017
ereport(ERROR,
20132018
(errcode(ERRCODE_CONNECTION_FAILURE),
2014-
errmsg("could not connect to publisher when attempting to "
2015-
"drop replication slot \"%s\": %s", slotname, err),
2019+
errmsg("could not connect to publisher when attempting to drop replication slot \"%s\": %s",
2020+
slotname, err),
20162021
/* translator: %s is an SQL ALTER command */
20172022
errhint("Use %s to disassociate the subscription from the slot.",
20182023
"ALTER SUBSCRIPTION ... SET (slot_name = NONE)")));

0 commit comments

Comments
 (0)