From e046136ef860ba06186388962a1e4096f9833a8d Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Sun, 16 Oct 2022 07:21:50 +0000 Subject: [PATCH v3] Disallow specifiying archive_library and archive_command GUCs at once The archive_library and archive_command GUCs are meant to be mutually exclusive because the users allowed to choose any one of the archiving approach by design. With the patch, the server emits an error if they both are set at once. Note that we've not chosen to emit the error from check_hook or assign_hook as it can have odd behaviors such as unexpected GUC ordering dependencies. Backpatch to 15. Author: Nathan Bossart Reviewed-by: Peter Eisentraut Reviewed-by: Bharath Rupireddy Discussion: https://www.postgresql.org/message-id/20220914222736.GA3042279%40nathanxps13 --- doc/src/sgml/config.sgml | 10 +++++++--- src/backend/postmaster/pgarch.c | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 66312b53b8..9d0f3608c4 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3597,9 +3597,11 @@ include_dir 'conf.d' This parameter can only be set in the postgresql.conf - file or on the server command line. It is ignored unless + file or on the server command line. It is only used if archive_mode was enabled at server start and - archive_library is set to an empty string. + archive_library is set to an empty string. If both + archive_command and archive_library + are set, archiving will fail. If archive_command is an empty string (the default) while archive_mode is enabled (and archive_library is set to an empty string), WAL archiving is temporarily @@ -3624,7 +3626,9 @@ include_dir 'conf.d' The library to use for archiving completed WAL file segments. If set to an empty string (the default), archiving via shell is enabled, and - is used. Otherwise, the specified + is used. If both + archive_command and archive_library + are set, archiving will fail. Otherwise, the specified shared library is used for archiving. For more information, see and . diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 3868cd7bd3..bba2bc07a9 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -803,10 +803,6 @@ HandlePgArchInterrupts(void) if (archiveLibChanged) { - /* - * Call the currently loaded archive module's shutdown callback, - * if one is defined. - */ call_archive_module_shutdown_callback(0, 0); /* @@ -823,6 +819,15 @@ HandlePgArchInterrupts(void) proc_exit(0); } + else if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0') + { + call_archive_module_shutdown_callback(0, 0); + + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("both archive_command and archive_library specified"), + errdetail("Only one of archive_command, archive_library may be set."))); + } } } @@ -836,6 +841,12 @@ LoadArchiveLibrary(void) { ArchiveModuleInit archive_init; + if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0') + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("both archive_command and archive_library specified"), + errdetail("Only one of archive_command, archive_library may be set."))); + memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks)); /* -- 2.34.1