postgres.git / summary / log / commit / refs
commit b00a16baeb2ab8551ae752e86263e1c0bfc52d9c
Author: Fujii Masao <fujii@postgresql.org>
Date: Wed Oct 22 11:13:15 2025 +0000
First released in: 13.23, 14.20, 15.15, 16.11, 17.7, 18.1
Make invalid primary_slot_name follow standard GUC error reporting.
Previously, if primary_slot_name was set to an invalid slot name and
the configuration file was reloaded, both the postmaster and all other
backend processes reported a WARNING. With many processes running,
this could produce a flood of duplicate messages. The problem was that
the GUC check hook for primary_slot_name reported errors at WARNING
level via ereport().
This commit changes the check hook to use GUC_check_errdetail() and
GUC_check_errhint() for error reporting. As with other GUC parameters,
this causes non-postmaster processes to log the message at DEBUG3,
so by default, only the postmaster's message appears in the log file.
Backpatch to all supported versions.
Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Chao Li <lic@highgo.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/CAHGQGwFud-cvthCTfusBfKHBS6Jj6kdAPTdLWKvP2qjUX6L_wA@mail.gmail.com
Backpatch-through: 13
src/backend/replication/slot.c | 59 +++++++++++++++++++++++++++++++-----------
src/backend/utils/misc/guc.c | 13 +++++++++-
src/include/replication/slot.h | 2 ++
3 files changed, 58 insertions(+), 16 deletions(-)
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index 4268c099045..bc3f99cacef 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -166,31 +166,62 @@ ReplicationSlotsShmemInit(void)
/*
* Check whether the passed slot name is valid and report errors at elevel.
*
+ * See comments for ReplicationSlotValidateNameInternal().
+ */
+bool
+ReplicationSlotValidateName(const char *name, int elevel)
+{
+ int err_code;
+ char *err_msg = NULL;
+ char *err_hint = NULL;
+
+ if (!ReplicationSlotValidateNameInternal(name, &err_code, &err_msg,
+ &err_hint))
+ {
+ ereport(elevel,
+ errcode(err_code),
+ errmsg_internal("%s", err_msg),
+ (err_hint != NULL) ? errhint("%s", err_hint) : 0);
+
+ pfree(err_msg);
+ if (err_hint != NULL)
+ pfree(err_hint);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * Check whether the passed slot name is valid.
+ *
* Slot names may consist out of [a-z0-9_]{1,NAMEDATALEN-1} which should allow
* the name to be used as a directory name on every supported OS.
*
- * Returns whether the directory name is valid or not if elevel < ERROR.
+ * Returns true if the slot name is valid. Otherwise, returns false and stores
+ * the error code, error message, and optional hint in err_code, err_msg, and
+ * err_hint, respectively. The caller is responsible for freeing err_msg and
+ * err_hint, which are palloc'd.
*/
bool
-ReplicationSlotValidateName(const char *name, int elevel)
+ReplicationSlotValidateNameInternal(const char *name, int *err_code,
+ char **err_msg, char **err_hint)
{
const char *cp;
if (strlen(name) == 0)
{
- ereport(elevel,
- (errcode(ERRCODE_INVALID_NAME),
- errmsg("replication slot name \"%s\" is too short",
- name)));
+ *err_code = ERRCODE_INVALID_NAME;
+ *err_msg = psprintf(_("replication slot name \"%s\" is too short"), name);
+ *err_hint = NULL;
return false;
}
if (strlen(name) >= NAMEDATALEN)
{
- ereport(elevel,
- (errcode(ERRCODE_NAME_TOO_LONG),
- errmsg("replication slot name \"%s\" is too long",
- name)));
+ *err_code = ERRCODE_NAME_TOO_LONG;
+ *err_msg = psprintf(_("replication slot name \"%s\" is too long"), name);
+ *err_hint = NULL;
return false;
}
@@ -200,11 +231,9 @@ ReplicationSlotValidateName(const char *name, int elevel)
|| (*cp >= '0' && *cp <= '9')
|| (*cp == '_')))
{
- ereport(elevel,
- (errcode(ERRCODE_INVALID_NAME),
- errmsg("replication slot name \"%s\" contains invalid character",
- name),
- errhint("Replication slot names may only contain lower case letters, numbers, and the underscore character.")));
+ *err_code = ERRCODE_INVALID_NAME;
+ *err_msg = psprintf(_("replication slot name \"%s\" contains invalid character"), name);
+ *err_hint = psprintf(_("Replication slot names may only contain lower case letters, numbers, and the underscore character."));
return false;
}
}
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 1fabbb11ffa..aa980b84f79 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -12128,9 +12128,20 @@ assign_recovery_target_lsn(const char *newval, void *extra)
static bool
check_primary_slot_name(char **newval, void **extra, GucSource source)
{
+ int err_code;
+ char *err_msg = NULL;
+ char *err_hint = NULL;
+
if (*newval && strcmp(*newval, "") != 0 &&
- !ReplicationSlotValidateName(*newval, WARNING))
+ !ReplicationSlotValidateNameInternal(*newval, &err_code, &err_msg,
+ &err_hint))
+ {
+ GUC_check_errcode(err_code);
+ GUC_check_errdetail("%s", err_msg);
+ if (err_hint != NULL)
+ GUC_check_errhint("%s", err_hint);
return false;
+ }
return true;
}
diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h
index 12c68ddbd2e..6004cbd70bb 100644
--- a/src/include/replication/slot.h
+++ b/src/include/replication/slot.h
@@ -203,6 +203,8 @@ extern void ReplicationSlotMarkDirty(void);
/* misc stuff */
extern bool ReplicationSlotValidateName(const char *name, int elevel);
+extern bool ReplicationSlotValidateNameInternal(const char *name,
+ int *err_code, char **err_msg, char **err_hint);
extern void ReplicationSlotReserveWal(void);
extern void ReplicationSlotsComputeRequiredXmin(bool already_locked);
extern void ReplicationSlotsComputeRequiredLSN(void);
[parent: 7d7ebdb800fe]