Skip to content

Commit 2648eab

Browse files
committed
pg_createsubscriber: reword dry-run log messages
The original messages were confusing in dry-run mode in that they state that something is being done, when in reality it isn't. Use alternative wording in that case, to make the distinction clear. Author: Peter Smith <[email protected]> Reviewed-by: Chao Li <[email protected]> Reviewed-by: Euler Taveira <[email protected]> Backpatch-through: 18 Discussion: https://postgr.es/m/CAHut+PsvQJQnQO0KT0S2oegenkvJ8FUuY-QS5syyqmT24R2xFQ@mail.gmail.com
1 parent 1114491 commit 2648eab

File tree

2 files changed

+75
-42
lines changed

2 files changed

+75
-42
lines changed

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ static void set_replication_progress(PGconn *conn, const struct LogicalRepInfo *
124124
static void enable_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo);
125125
static void check_and_drop_existing_subscriptions(PGconn *conn,
126126
const struct LogicalRepInfo *dbinfo);
127-
static void drop_existing_subscriptions(PGconn *conn, const char *subname,
128-
const char *dbname);
127+
static void drop_existing_subscription(PGconn *conn, const char *subname,
128+
const char *dbname);
129129
static void get_publisher_databases(struct CreateSubscriberOptions *opt,
130130
bool dbnamespecified);
131131

@@ -688,13 +688,20 @@ modify_subscriber_sysid(const struct CreateSubscriberOptions *opt)
688688
cf->system_identifier |= ((uint64) tv.tv_usec) << 12;
689689
cf->system_identifier |= getpid() & 0xFFF;
690690

691-
if (!dry_run)
691+
if (dry_run)
692+
pg_log_info("dry-run: would set system identifier to %" PRIu64 " on subscriber",
693+
cf->system_identifier);
694+
else
695+
{
692696
update_controlfile(subscriber_dir, cf, true);
697+
pg_log_info("system identifier is %" PRIu64 " on subscriber",
698+
cf->system_identifier);
699+
}
693700

694-
pg_log_info("system identifier is %" PRIu64 " on subscriber",
695-
cf->system_identifier);
696-
697-
pg_log_info("running pg_resetwal on the subscriber");
701+
if (dry_run)
702+
pg_log_info("dry-run: would run pg_resetwal on the subscriber");
703+
else
704+
pg_log_info("running pg_resetwal on the subscriber");
698705

699706
cmd_str = psprintf("\"%s\" -D \"%s\" > \"%s\"", pg_resetwal_path,
700707
subscriber_dir, DEVNULL);
@@ -983,9 +990,9 @@ check_publisher(const struct LogicalRepInfo *dbinfo)
983990
}
984991

985992
/*
986-
* Validate 'max_slot_wal_keep_size'. If this parameter is set to a
987-
* non-default value, it may cause replication failures due to required
988-
* WAL files being prematurely removed.
993+
* In dry-run mode, validate 'max_slot_wal_keep_size'. If this parameter
994+
* is set to a non-default value, it may cause replication failures due to
995+
* required WAL files being prematurely removed.
989996
*/
990997
if (dry_run && (strcmp(max_slot_wal_keep_size, "-1") != 0))
991998
{
@@ -1113,7 +1120,7 @@ check_subscriber(const struct LogicalRepInfo *dbinfo)
11131120
* node.
11141121
*/
11151122
static void
1116-
drop_existing_subscriptions(PGconn *conn, const char *subname, const char *dbname)
1123+
drop_existing_subscription(PGconn *conn, const char *subname, const char *dbname)
11171124
{
11181125
PQExpBuffer query = createPQExpBuffer();
11191126
PGresult *res;
@@ -1130,11 +1137,14 @@ drop_existing_subscriptions(PGconn *conn, const char *subname, const char *dbnam
11301137
subname);
11311138
appendPQExpBuffer(query, " DROP SUBSCRIPTION %s;", subname);
11321139

1133-
pg_log_info("dropping subscription \"%s\" in database \"%s\"",
1134-
subname, dbname);
1135-
1136-
if (!dry_run)
1140+
if (dry_run)
1141+
pg_log_info("dry-run: would drop subscription \"%s\" in database \"%s\"",
1142+
subname, dbname);
1143+
else
11371144
{
1145+
pg_log_info("dropping subscription \"%s\" in database \"%s\"",
1146+
subname, dbname);
1147+
11381148
res = PQexec(conn, query->data);
11391149

11401150
if (PQresultStatus(res) != PGRES_COMMAND_OK)
@@ -1180,8 +1190,8 @@ check_and_drop_existing_subscriptions(PGconn *conn,
11801190
}
11811191

11821192
for (int i = 0; i < PQntuples(res); i++)
1183-
drop_existing_subscriptions(conn, PQgetvalue(res, i, 0),
1184-
dbinfo->dbname);
1193+
drop_existing_subscription(conn, PQgetvalue(res, i, 0),
1194+
dbinfo->dbname);
11851195

11861196
PQclear(res);
11871197
destroyPQExpBuffer(query);
@@ -1275,7 +1285,7 @@ setup_recovery(const struct LogicalRepInfo *dbinfo, const char *datadir, const c
12751285

12761286
if (dry_run)
12771287
{
1278-
appendPQExpBufferStr(recoveryconfcontents, "# dry run mode");
1288+
appendPQExpBufferStr(recoveryconfcontents, "# dry run mode\n");
12791289
appendPQExpBuffer(recoveryconfcontents,
12801290
"recovery_target_lsn = '%X/%08X'\n",
12811291
LSN_FORMAT_ARGS((XLogRecPtr) InvalidXLogRecPtr));
@@ -1381,8 +1391,12 @@ create_logical_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo)
13811391

13821392
Assert(conn != NULL);
13831393

1384-
pg_log_info("creating the replication slot \"%s\" in database \"%s\" on publisher",
1385-
slot_name, dbinfo->dbname);
1394+
if (dry_run)
1395+
pg_log_info("dry-run: would create the replication slot \"%s\" in database \"%s\" on publisher",
1396+
slot_name, dbinfo->dbname);
1397+
else
1398+
pg_log_info("creating the replication slot \"%s\" in database \"%s\" on publisher",
1399+
slot_name, dbinfo->dbname);
13861400

13871401
slot_name_esc = PQescapeLiteral(conn, slot_name, strlen(slot_name));
13881402

@@ -1430,8 +1444,12 @@ drop_replication_slot(PGconn *conn, struct LogicalRepInfo *dbinfo,
14301444

14311445
Assert(conn != NULL);
14321446

1433-
pg_log_info("dropping the replication slot \"%s\" in database \"%s\"",
1434-
slot_name, dbinfo->dbname);
1447+
if (dry_run)
1448+
pg_log_info("dry-run: would drop the replication slot \"%s\" in database \"%s\"",
1449+
slot_name, dbinfo->dbname);
1450+
else
1451+
pg_log_info("dropping the replication slot \"%s\" in database \"%s\"",
1452+
slot_name, dbinfo->dbname);
14351453

14361454
slot_name_esc = PQescapeLiteral(conn, slot_name, strlen(slot_name));
14371455

@@ -1575,13 +1593,8 @@ wait_for_end_recovery(const char *conninfo, const struct CreateSubscriberOptions
15751593

15761594
for (;;)
15771595
{
1578-
bool in_recovery = server_is_in_recovery(conn);
1579-
1580-
/*
1581-
* Does the recovery process finish? In dry run mode, there is no
1582-
* recovery mode. Bail out as the recovery process has ended.
1583-
*/
1584-
if (!in_recovery || dry_run)
1596+
/* Did the recovery process finish? We're done if so. */
1597+
if (dry_run || !server_is_in_recovery(conn))
15851598
{
15861599
status = POSTMASTER_READY;
15871600
recovery_ended = true;
@@ -1657,8 +1670,12 @@ create_publication(PGconn *conn, struct LogicalRepInfo *dbinfo)
16571670
PQclear(res);
16581671
resetPQExpBuffer(str);
16591672

1660-
pg_log_info("creating publication \"%s\" in database \"%s\"",
1661-
dbinfo->pubname, dbinfo->dbname);
1673+
if (dry_run)
1674+
pg_log_info("dry-run: would create publication \"%s\" in database \"%s\"",
1675+
dbinfo->pubname, dbinfo->dbname);
1676+
else
1677+
pg_log_info("creating publication \"%s\" in database \"%s\"",
1678+
dbinfo->pubname, dbinfo->dbname);
16621679

16631680
appendPQExpBuffer(str, "CREATE PUBLICATION %s FOR ALL TABLES",
16641681
ipubname_esc);
@@ -1700,8 +1717,12 @@ drop_publication(PGconn *conn, const char *pubname, const char *dbname,
17001717

17011718
pubname_esc = PQescapeIdentifier(conn, pubname, strlen(pubname));
17021719

1703-
pg_log_info("dropping publication \"%s\" in database \"%s\"",
1704-
pubname, dbname);
1720+
if (dry_run)
1721+
pg_log_info("dry-run: would drop publication \"%s\" in database \"%s\"",
1722+
pubname, dbname);
1723+
else
1724+
pg_log_info("dropping publication \"%s\" in database \"%s\"",
1725+
pubname, dbname);
17051726

17061727
appendPQExpBuffer(str, "DROP PUBLICATION %s", pubname_esc);
17071728

@@ -1809,8 +1830,12 @@ create_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo)
18091830
pubconninfo_esc = PQescapeLiteral(conn, dbinfo->pubconninfo, strlen(dbinfo->pubconninfo));
18101831
replslotname_esc = PQescapeLiteral(conn, dbinfo->replslotname, strlen(dbinfo->replslotname));
18111832

1812-
pg_log_info("creating subscription \"%s\" in database \"%s\"",
1813-
dbinfo->subname, dbinfo->dbname);
1833+
if (dry_run)
1834+
pg_log_info("dry-run: would create subscription \"%s\" in database \"%s\"",
1835+
dbinfo->subname, dbinfo->dbname);
1836+
else
1837+
pg_log_info("creating subscription \"%s\" in database \"%s\"",
1838+
dbinfo->subname, dbinfo->dbname);
18141839

18151840
appendPQExpBuffer(str,
18161841
"CREATE SUBSCRIPTION %s CONNECTION %s PUBLICATION %s "
@@ -1907,8 +1932,12 @@ set_replication_progress(PGconn *conn, const struct LogicalRepInfo *dbinfo, cons
19071932
*/
19081933
originname = psprintf("pg_%u", suboid);
19091934

1910-
pg_log_info("setting the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
1911-
originname, lsnstr, dbinfo->dbname);
1935+
if (dry_run)
1936+
pg_log_info("dry-run: would set the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
1937+
originname, lsnstr, dbinfo->dbname);
1938+
else
1939+
pg_log_info("setting the replication progress (node name \"%s\", LSN %s) in database \"%s\"",
1940+
originname, lsnstr, dbinfo->dbname);
19121941

19131942
resetPQExpBuffer(str);
19141943
appendPQExpBuffer(str,
@@ -1953,8 +1982,12 @@ enable_subscription(PGconn *conn, const struct LogicalRepInfo *dbinfo)
19531982

19541983
subname = PQescapeIdentifier(conn, dbinfo->subname, strlen(dbinfo->subname));
19551984

1956-
pg_log_info("enabling subscription \"%s\" in database \"%s\"",
1957-
dbinfo->subname, dbinfo->dbname);
1985+
if (dry_run)
1986+
pg_log_info("dry-run: would enable subscription \"%s\" in database \"%s\"",
1987+
dbinfo->subname, dbinfo->dbname);
1988+
else
1989+
pg_log_info("enabling subscription \"%s\" in database \"%s\"",
1990+
dbinfo->subname, dbinfo->dbname);
19581991

19591992
appendPQExpBuffer(str, "ALTER SUBSCRIPTION %s ENABLE", subname);
19601993

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ sub generate_db
436436

437437
# Verify that the required logical replication objects are output.
438438
# The expected count 3 refers to postgres, $db1 and $db2 databases.
439-
is(scalar(() = $stderr =~ /creating publication/g),
439+
is(scalar(() = $stderr =~ /would create publication/g),
440440
3, "verify publications are created for all databases");
441-
is(scalar(() = $stderr =~ /creating the replication slot/g),
441+
is(scalar(() = $stderr =~ /would create the replication slot/g),
442442
3, "verify replication slots are created for all databases");
443-
is(scalar(() = $stderr =~ /creating subscription/g),
443+
is(scalar(() = $stderr =~ /would create subscription/g),
444444
3, "verify subscriptions are created for all databases");
445445

446446
# Run pg_createsubscriber on node S. --verbose is used twice

0 commit comments

Comments
 (0)