mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
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
This commit is contained in:
@@ -4761,9 +4761,20 @@ RecoveryRequiresIntParameter(const char *param_name, int currValue, int minValue
|
|||||||
bool
|
bool
|
||||||
check_primary_slot_name(char **newval, void **extra, GucSource source)
|
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 &&
|
if (*newval && strcmp(*newval, "") != 0 &&
|
||||||
!ReplicationSlotValidateName(*newval, false, WARNING))
|
!ReplicationSlotValidateNameInternal(*newval, false, &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 false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,35 +260,72 @@ ReplicationSlotShmemExit(int code, Datum arg)
|
|||||||
/*
|
/*
|
||||||
* Check whether the passed slot name is valid and report errors at elevel.
|
* Check whether the passed slot name is valid and report errors at elevel.
|
||||||
*
|
*
|
||||||
|
* See comments for ReplicationSlotValidateNameInternal().
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
ReplicationSlotValidateName(const char *name, bool allow_reserved_name,
|
||||||
|
int elevel)
|
||||||
|
{
|
||||||
|
int err_code;
|
||||||
|
char *err_msg = NULL;
|
||||||
|
char *err_hint = NULL;
|
||||||
|
|
||||||
|
if (!ReplicationSlotValidateNameInternal(name, allow_reserved_name,
|
||||||
|
&err_code, &err_msg, &err_hint))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Use errmsg_internal() and errhint_internal() instead of errmsg()
|
||||||
|
* and errhint(), since the messages from
|
||||||
|
* ReplicationSlotValidateNameInternal() are already translated. This
|
||||||
|
* avoids double translation.
|
||||||
|
*/
|
||||||
|
ereport(elevel,
|
||||||
|
errcode(err_code),
|
||||||
|
errmsg_internal("%s", err_msg),
|
||||||
|
(err_hint != NULL) ? errhint_internal("%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.
|
||||||
|
*
|
||||||
* An error will be reported for a reserved replication slot name if
|
* An error will be reported for a reserved replication slot name if
|
||||||
* allow_reserved_name is set to false.
|
* allow_reserved_name is set to false.
|
||||||
*
|
*
|
||||||
* Slot names may consist out of [a-z0-9_]{1,NAMEDATALEN-1} which should allow
|
* 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.
|
* 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
|
bool
|
||||||
ReplicationSlotValidateName(const char *name, bool allow_reserved_name,
|
ReplicationSlotValidateNameInternal(const char *name, bool allow_reserved_name,
|
||||||
int elevel)
|
int *err_code, char **err_msg, char **err_hint)
|
||||||
{
|
{
|
||||||
const char *cp;
|
const char *cp;
|
||||||
|
|
||||||
if (strlen(name) == 0)
|
if (strlen(name) == 0)
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
*err_code = ERRCODE_INVALID_NAME;
|
||||||
(errcode(ERRCODE_INVALID_NAME),
|
*err_msg = psprintf(_("replication slot name \"%s\" is too short"), name);
|
||||||
errmsg("replication slot name \"%s\" is too short",
|
*err_hint = NULL;
|
||||||
name)));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(name) >= NAMEDATALEN)
|
if (strlen(name) >= NAMEDATALEN)
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
*err_code = ERRCODE_NAME_TOO_LONG;
|
||||||
(errcode(ERRCODE_NAME_TOO_LONG),
|
*err_msg = psprintf(_("replication slot name \"%s\" is too long"), name);
|
||||||
errmsg("replication slot name \"%s\" is too long",
|
*err_hint = NULL;
|
||||||
name)));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,24 +335,19 @@ ReplicationSlotValidateName(const char *name, bool allow_reserved_name,
|
|||||||
|| (*cp >= '0' && *cp <= '9')
|
|| (*cp >= '0' && *cp <= '9')
|
||||||
|| (*cp == '_')))
|
|| (*cp == '_')))
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
*err_code = ERRCODE_INVALID_NAME;
|
||||||
(errcode(ERRCODE_INVALID_NAME),
|
*err_msg = psprintf(_("replication slot name \"%s\" contains invalid character"), name);
|
||||||
errmsg("replication slot name \"%s\" contains invalid character",
|
*err_hint = psprintf(_("Replication slot names may only contain lower case letters, numbers, and the underscore character."));
|
||||||
name),
|
|
||||||
errhint("Replication slot names may only contain lower case letters, numbers, and the underscore character.")));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allow_reserved_name && IsSlotForConflictCheck(name))
|
if (!allow_reserved_name && IsSlotForConflictCheck(name))
|
||||||
{
|
{
|
||||||
ereport(elevel,
|
*err_code = ERRCODE_RESERVED_NAME;
|
||||||
errcode(ERRCODE_RESERVED_NAME),
|
*err_msg = psprintf(_("replication slot name \"%s\" is reserved"), name);
|
||||||
errmsg("replication slot name \"%s\" is reserved",
|
*err_hint = psprintf(_("The name \"%s\" is reserved for the conflict detection slot."),
|
||||||
name),
|
CONFLICT_DETECTION_SLOT);
|
||||||
errdetail("The name \"%s\" is reserved for the conflict detection slot.",
|
|
||||||
CONFLICT_DETECTION_SLOT));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -321,6 +321,9 @@ extern void ReplicationSlotInitialize(void);
|
|||||||
extern bool ReplicationSlotValidateName(const char *name,
|
extern bool ReplicationSlotValidateName(const char *name,
|
||||||
bool allow_reserved_name,
|
bool allow_reserved_name,
|
||||||
int elevel);
|
int elevel);
|
||||||
|
extern bool ReplicationSlotValidateNameInternal(const char *name,
|
||||||
|
bool allow_reserved_name,
|
||||||
|
int *err_code, char **err_msg, char **err_hint);
|
||||||
extern void ReplicationSlotReserveWal(void);
|
extern void ReplicationSlotReserveWal(void);
|
||||||
extern void ReplicationSlotsComputeRequiredXmin(bool already_locked);
|
extern void ReplicationSlotsComputeRequiredXmin(bool already_locked);
|
||||||
extern void ReplicationSlotsComputeRequiredLSN(void);
|
extern void ReplicationSlotsComputeRequiredLSN(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user