When pg_upgrade checks the new cluster for logical slot migration, two
errors say that a setting is too low or invalid, but do not say where
to change it. Add a short second line to each message that names the
setting and the cluster, and, for max_replication_slots, the smallest
value that works. This is the same guidance that pg_createsubscriber
already gives with pg_log_error_hint().
pg_upgrade has its own pg_fatal() that does not support hints, so the
guidance is part of the message, as in other checks in check.c.
Cover the new wording in 003_logical_slots.pl and 004_subscription.pl,
and add a test for the wal_level = minimal case, which had none.
---
Hi,
While reading check_new_cluster_replication_slots() in pg_upgrade, I saw that
some errors say a setting is wrong but do not say what to change or in which
cluster. For example:
"wal_level" must be "replica" or "logical" but is set to "minimal"
"max_replication_slots" (0) must be greater than or equal to the number of
logical replication slots (1) in the old cluster
pg_createsubscriber already adds a hint for similar cases ("Increase the
configuration parameter ..."). pg_upgrade has its own pg_fatal() without hint
support, so the attached patch adds a second line inside the message. Some
other checks in check.c already put guidance in the message (for example the
datallowconn one). It names the setting, says "in the new cluster", and gives
the minimum value for the numeric ones. I did the same for the slots + 1
variant (retain dead tuples).
Before/after:
"max_replication_slots" (0) must be ... (1) in the old cluster
Increase "max_replication_slots" in the new cluster to at least 1.
The patch also adds a test for wal_level = minimal in 003_logical_slots.pl and
updates the regex for max_replication_slots in 003 and in 004_subscription.pl
(slots + 1 variant). On my build, make check (243 tests), the pg_upgrade TAP
tests (9 files, 172 tests), and pgindent on check.c pass. perltidy (an older
version) shows no diff on the two .pl files. I also fixed a comment number in
003 ("(2)" to "(3)"). With only the test changes and unpatched check.c, the new
checks fail as expected.
Does this direction make sense? I can add a "Hint:" prefix, or split the patch
if you prefer.
What I did not test:
- Windows and non-English locales (translations will need updates).
- Only one build (Debian, gcc, cassert).
- perltidy was v20220613, not the 20230309 version the tree asks for.
Thanks,
Joao Rito
Edicoes pelo revisor (r174, mantidas): email com 'some other checks' (nao 'like
other checks do'), slots+1 citado, testes que rodaram. Rodada final: origins
removido, slots+1 provado, controle negativo e perltidy feitos.
r176 (re-revisao): removida do email a frase sobre
max_active_replication_origins (pergunta final e item "did not test"); perltidy
descrito como "older version, no diff"; citado o ajuste de comentario
"(2)"->"(3)".
src/bin/pg_upgrade/check.c | 13 ++++++++-----
src/bin/pg_upgrade/t/003_logical_slots.pl | 21 +++++++++++++++++++--
src/bin/pg_upgrade/t/004_subscription.pl | 2 +-
3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c
index 2d4aaf2..e041894 100644
--- a/src/bin/pg_upgrade/check.c
+++ b/src/bin/pg_upgrade/check.c
@@ -2160,7 +2160,8 @@ check_new_cluster_replication_slots(void)
if ((nslots_on_old > 0 || old_cluster.sub_retain_dead_tuples) &&
strcmp(wal_level, "minimal") == 0)
- pg_fatal("\"wal_level\" must be \"replica\" or \"logical\" but
is set to \"%s\"",
+ pg_fatal("\"wal_level\" must be \"replica\" or \"logical\" but
is set to \"%s\"\n"
+ "Set \"wal_level\" to \"replica\" or
\"logical\" in the new cluster.",
wal_level);
output_plugin_libraries = PQgetvalue(res, 1, 0);
@@ -2247,13 +2248,15 @@ check_new_cluster_replication_slots(void)
nslots_on_old + 1 > max_replication_slots)
pg_fatal("\"max_replication_slots\" (%d) must be greater than
or equal to the number of "
"logical replication slots in the old cluster
plus one additional slot required "
- "for retaining conflict detection information
(%d)",
- max_replication_slots, nslots_on_old + 1);
+ "for retaining conflict detection information
(%d)\n"
+ "Increase \"max_replication_slots\" in the new
cluster to at least %d.",
+ max_replication_slots, nslots_on_old + 1,
nslots_on_old + 1);
if (nslots_on_old > max_replication_slots)
pg_fatal("\"max_replication_slots\" (%d) must be greater than
or equal to the number of "
- "logical replication slots (%d) in the old
cluster",
- max_replication_slots, nslots_on_old);
+ "logical replication slots (%d) in the old
cluster\n"
+ "Increase \"max_replication_slots\" in the new
cluster to at least %d.",
+ max_replication_slots, nslots_on_old,
nslots_on_old);
PQclear(res);
PQfinish(conn);
diff --git a/src/bin/pg_upgrade/t/003_logical_slots.pl
b/src/bin/pg_upgrade/t/003_logical_slots.pl
index 01ab824..ce60151 100644
--- a/src/bin/pg_upgrade/t/003_logical_slots.pl
+++ b/src/bin/pg_upgrade/t/003_logical_slots.pl
@@ -68,7 +68,24 @@ $oldpub->safe_psql(
]);
$oldpub->stop();
-# 2. Set 'max_replication_slots' to be less than the number of slots (2)
+# 2. Set 'wal_level' to minimal in the new cluster. Logical slots cannot be
+# upgraded then, and pg_upgrade must tell how to fix it.
+$newpub->append_conf('postgresql.conf',
+ "wal_level = minimal\nmax_wal_senders = 0");
+
+command_checks_all(
+ [@pg_upgrade_cmd],
+ 1,
+ [
+ qr/"wal_level" must be "replica" or "logical" but is set to
"minimal"\nSet "wal_level" to "replica" or "logical" in the new cluster\./
+ ],
+ [qr//],
+ 'run of pg_upgrade where the new cluster has "wal_level" set to
minimal');
+
+$newpub->append_conf('postgresql.conf',
+ "wal_level = logical\nmax_wal_senders = 10");
+
+# 3. Set 'max_replication_slots' to be less than the number of slots (3)
# present in the old cluster.
$newpub->append_conf('postgresql.conf', "max_replication_slots = 1");
@@ -78,7 +95,7 @@ command_checks_all(
[@pg_upgrade_cmd],
1,
[
- qr/"max_replication_slots" \(1\) must be greater than or equal
to the number of logical replication slots \(3\) in the old cluster/
+ qr/"max_replication_slots" \(1\) must be greater than or equal
to the number of logical replication slots \(3\) in the old cluster\nIncrease
"max_replication_slots" in the new cluster to at least 3\./
],
[qr//],
'run of pg_upgrade where the new cluster has insufficient
"max_replication_slots"'
diff --git a/src/bin/pg_upgrade/t/004_subscription.pl
b/src/bin/pg_upgrade/t/004_subscription.pl
index 36f059f..f578a3c 100644
--- a/src/bin/pg_upgrade/t/004_subscription.pl
+++ b/src/bin/pg_upgrade/t/004_subscription.pl
@@ -123,7 +123,7 @@ command_checks_all(
],
1,
[
- qr/"max_replication_slots" \(0\) must be greater than or equal
to the number of logical replication slots in the old cluster plus one
additional slot required for retaining conflict detection information \(1\)/
+ qr/"max_replication_slots" \(0\) must be greater than or equal
to the number of logical replication slots in the old cluster plus one
additional slot required for retaining conflict detection information
\(1\)\nIncrease "max_replication_slots" in the new cluster to at least 1\./
],
[qr//],
'run of pg_upgrade where the new cluster has insufficient
max_replication_slots'
--
2.39.5