Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60dda7b

Browse files
committed
pg_createsubscriber: Rename option --remove to --clean
After discussion, the name --remove was suboptimally chosen. --clean has more precedent in other PostgreSQL tools. Reviewed-by: Hayato Kuroda (Fujitsu) <[email protected]> Discussion: https://www.postgresql.org/message-id/[email protected]
1 parent 0cd69b3 commit 60dda7b

File tree

3 files changed

+49
-50
lines changed

3 files changed

+49
-50
lines changed

doc/src/sgml/ref/pg_createsubscriber.sgml

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -169,36 +169,6 @@ PostgreSQL documentation
169169
</listitem>
170170
</varlistentry>
171171

172-
<varlistentry>
173-
<term><option>-R <replaceable class="parameter">objtype</replaceable></option></term>
174-
<term><option>--remove=<replaceable class="parameter">objtype</replaceable></option></term>
175-
<listitem>
176-
<para>
177-
Remove all objects of the specified type from specified databases on the
178-
target server.
179-
</para>
180-
<para>
181-
<itemizedlist>
182-
<listitem>
183-
<para>
184-
<literal>publications</literal>:
185-
The <literal>FOR ALL TABLES</literal> publications established for this
186-
subscriber are always removed; specifying this object type causes all
187-
other publications replicated from the source server to be dropped as
188-
well.
189-
</para>
190-
</listitem>
191-
</itemizedlist>
192-
</para>
193-
<para>
194-
The objects selected to be dropped are individually logged, including during
195-
a <option>--dry-run</option>. There is no opportunity to affect or stop the
196-
dropping of the selected objects, so consider taking a backup of them
197-
using <application>pg_dump</application>.
198-
</para>
199-
</listitem>
200-
</varlistentry>
201-
202172
<varlistentry>
203173
<term><option>-s <replaceable class="parameter">dir</replaceable></option></term>
204174
<term><option>--socketdir=<replaceable class="parameter">dir</replaceable></option></term>
@@ -259,6 +229,35 @@ PostgreSQL documentation
259229
</listitem>
260230
</varlistentry>
261231

232+
<varlistentry>
233+
<term><option>--clean=<replaceable class="parameter">objtype</replaceable></option></term>
234+
<listitem>
235+
<para>
236+
Drop all objects of the specified type from specified databases on the
237+
target server.
238+
</para>
239+
<para>
240+
<itemizedlist>
241+
<listitem>
242+
<para>
243+
<literal>publications</literal>:
244+
The <literal>FOR ALL TABLES</literal> publications established for this
245+
subscriber are always dropped; specifying this object type causes all
246+
other publications replicated from the source server to be dropped as
247+
well.
248+
</para>
249+
</listitem>
250+
</itemizedlist>
251+
</para>
252+
<para>
253+
The objects selected to be dropped are individually logged, including during
254+
a <option>--dry-run</option>. There is no opportunity to affect or stop the
255+
dropping of the selected objects, so consider taking a backup of them
256+
using <application>pg_dump</application>.
257+
</para>
258+
</listitem>
259+
</varlistentry>
260+
262261
<varlistentry>
263262
<term><option>--config-file=<replaceable class="parameter">filename</replaceable></option></term>
264263
<listitem>

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct CreateSubscriberOptions
4646
SimpleStringList replslot_names; /* list of replication slot names */
4747
int recovery_timeout; /* stop recovery after this time */
4848
bool all_dbs; /* all option */
49-
SimpleStringList objecttypes_to_remove; /* list of object types to remove */
49+
SimpleStringList objecttypes_to_clean; /* list of object types to cleanup */
5050
};
5151

5252
/* per-database publication/subscription info */
@@ -71,8 +71,8 @@ struct LogicalRepInfos
7171
{
7272
struct LogicalRepInfo *dbinfo;
7373
bool two_phase; /* enable-two-phase option */
74-
bits32 objecttypes_to_remove; /* flags indicating which object types
75-
* to remove on subscriber */
74+
bits32 objecttypes_to_clean; /* flags indicating which object types
75+
* to clean up on subscriber */
7676
};
7777

7878
static void cleanup_objects_atexit(void);
@@ -253,13 +253,13 @@ usage(void)
253253
printf(_(" -n, --dry-run dry run, just show what would be done\n"));
254254
printf(_(" -p, --subscriber-port=PORT subscriber port number (default %s)\n"), DEFAULT_SUB_PORT);
255255
printf(_(" -P, --publisher-server=CONNSTR publisher connection string\n"));
256-
printf(_(" -R, --remove=OBJECTTYPE remove all objects of the specified type from specified\n"
257-
" databases on the subscriber; accepts: \"%s\"\n"), "publications");
258256
printf(_(" -s, --socketdir=DIR socket directory to use (default current dir.)\n"));
259257
printf(_(" -t, --recovery-timeout=SECS seconds to wait for recovery to end\n"));
260258
printf(_(" -T, --enable-two-phase enable two-phase commit for all subscriptions\n"));
261259
printf(_(" -U, --subscriber-username=NAME user name for subscriber connection\n"));
262260
printf(_(" -v, --verbose output verbose messages\n"));
261+
printf(_(" --clean=OBJECTTYPE drop all objects of the specified type from specified\n"
262+
" databases on the subscriber; accepts: \"%s\"\n"), "publications");
263263
printf(_(" --config-file=FILENAME use specified main server configuration\n"
264264
" file when running target cluster\n"));
265265
printf(_(" --publication=NAME publication name\n"));
@@ -1730,7 +1730,7 @@ static void
17301730
check_and_drop_publications(PGconn *conn, struct LogicalRepInfo *dbinfo)
17311731
{
17321732
PGresult *res;
1733-
bool drop_all_pubs = dbinfos.objecttypes_to_remove & OBJECTTYPE_PUBLICATIONS;
1733+
bool drop_all_pubs = dbinfos.objecttypes_to_clean & OBJECTTYPE_PUBLICATIONS;
17341734

17351735
Assert(conn != NULL);
17361736

@@ -2026,7 +2026,6 @@ main(int argc, char **argv)
20262026
{"dry-run", no_argument, NULL, 'n'},
20272027
{"subscriber-port", required_argument, NULL, 'p'},
20282028
{"publisher-server", required_argument, NULL, 'P'},
2029-
{"remove", required_argument, NULL, 'R'},
20302029
{"socketdir", required_argument, NULL, 's'},
20312030
{"recovery-timeout", required_argument, NULL, 't'},
20322031
{"enable-two-phase", no_argument, NULL, 'T'},
@@ -2038,6 +2037,7 @@ main(int argc, char **argv)
20382037
{"publication", required_argument, NULL, 2},
20392038
{"replication-slot", required_argument, NULL, 3},
20402039
{"subscription", required_argument, NULL, 4},
2040+
{"clean", required_argument, NULL, 5},
20412041
{NULL, 0, NULL, 0}
20422042
};
20432043

@@ -2109,7 +2109,7 @@ main(int argc, char **argv)
21092109

21102110
get_restricted_token();
21112111

2112-
while ((c = getopt_long(argc, argv, "ad:D:np:P:R:s:t:TU:v",
2112+
while ((c = getopt_long(argc, argv, "ad:D:np:P:s:t:TU:v",
21132113
long_options, &option_index)) != -1)
21142114
{
21152115
switch (c)
@@ -2139,12 +2139,6 @@ main(int argc, char **argv)
21392139
case 'P':
21402140
opt.pub_conninfo_str = pg_strdup(optarg);
21412141
break;
2142-
case 'R':
2143-
if (!simple_string_list_member(&opt.objecttypes_to_remove, optarg))
2144-
simple_string_list_append(&opt.objecttypes_to_remove, optarg);
2145-
else
2146-
pg_fatal("object type \"%s\" specified more than once for -R/--remove", optarg);
2147-
break;
21482142
case 's':
21492143
opt.socket_dir = pg_strdup(optarg);
21502144
canonicalize_path(opt.socket_dir);
@@ -2191,6 +2185,12 @@ main(int argc, char **argv)
21912185
else
21922186
pg_fatal("subscription \"%s\" specified more than once for --subscription", optarg);
21932187
break;
2188+
case 5:
2189+
if (!simple_string_list_member(&opt.objecttypes_to_clean, optarg))
2190+
simple_string_list_append(&opt.objecttypes_to_clean, optarg);
2191+
else
2192+
pg_fatal("object type \"%s\" specified more than once for --clean", optarg);
2193+
break;
21942194
default:
21952195
/* getopt_long already emitted a complaint */
21962196
pg_log_error_hint("Try \"%s --help\" for more information.", progname);
@@ -2334,13 +2334,13 @@ main(int argc, char **argv)
23342334
}
23352335

23362336
/* Verify the object types specified for removal from the subscriber */
2337-
for (SimpleStringListCell *cell = opt.objecttypes_to_remove.head; cell; cell = cell->next)
2337+
for (SimpleStringListCell *cell = opt.objecttypes_to_clean.head; cell; cell = cell->next)
23382338
{
23392339
if (pg_strcasecmp(cell->val, "publications") == 0)
2340-
dbinfos.objecttypes_to_remove |= OBJECTTYPE_PUBLICATIONS;
2340+
dbinfos.objecttypes_to_clean |= OBJECTTYPE_PUBLICATIONS;
23412341
else
23422342
{
2343-
pg_log_error("invalid object type \"%s\" specified for -R/--remove", cell->val);
2343+
pg_log_error("invalid object type \"%s\" specified for --clean", cell->val);
23442344
pg_log_error_hint("The valid value is: \"%s\"", "publications");
23452345
exit(1);
23462346
}

src/bin/pg_basebackup/t/040_pg_createsubscriber.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ sub generate_db
331331
$node_p->wait_for_replay_catchup($node_s);
332332

333333
# Create user-defined publications, wait for streaming replication to sync them
334-
# to the standby, then verify that '--remove'
334+
# to the standby, then verify that '--clean'
335335
# removes them.
336336
$node_p->safe_psql(
337337
$db1, qq(
@@ -446,7 +446,7 @@ sub generate_db
446446
# Run pg_createsubscriber on node S. --verbose is used twice
447447
# to show more information.
448448
# In passing, also test the --enable-two-phase option and
449-
# --remove option
449+
# --clean option
450450
command_ok(
451451
[
452452
'pg_createsubscriber',
@@ -463,7 +463,7 @@ sub generate_db
463463
'--database' => $db1,
464464
'--database' => $db2,
465465
'--enable-two-phase',
466-
'--remove' => 'publications',
466+
'--clean' => 'publications',
467467
],
468468
'run pg_createsubscriber on node S');
469469

0 commit comments

Comments
 (0)