v3-0001-Disallow-specifiying-archive_library-and-archive_.patch

application/octet-stream

Filename: v3-0001-Disallow-specifiying-archive_library-and-archive_.patch
Type: application/octet-stream
Part: 0
Message: Re: archive modules

Patch

Format: format-patch
Series: patch v3-0001
Subject: Disallow specifiying archive_library and archive_command GUCs at once
File+
doc/src/sgml/config.sgml 7 3
src/backend/postmaster/pgarch.c 15 4
From e046136ef860ba06186388962a1e4096f9833a8d Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
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'
        </para>
        <para>
         This parameter can only be set in the <filename>postgresql.conf</filename>
-        file or on the server command line.  It is ignored unless
+        file or on the server command line.  It is only used if
         <varname>archive_mode</varname> was enabled at server start and
-        <varname>archive_library</varname> is set to an empty string.
+        <varname>archive_library</varname> is set to an empty string.  If both
+        <varname>archive_command</varname> and <varname>archive_library</varname>
+        are set, archiving will fail.
         If <varname>archive_command</varname> is an empty string (the default) while
         <varname>archive_mode</varname> is enabled (and <varname>archive_library</varname>
         is set to an empty string), WAL archiving is temporarily
@@ -3624,7 +3626,9 @@ include_dir 'conf.d'
        <para>
         The library to use for archiving completed WAL file segments.  If set to
         an empty string (the default), archiving via shell is enabled, and
-        <xref linkend="guc-archive-command"/> is used.  Otherwise, the specified
+        <xref linkend="guc-archive-command"/> is used.  If both
+        <varname>archive_command</varname> and <varname>archive_library</varname>
+        are set, archiving will fail.  Otherwise, the specified
         shared library is used for archiving.  For more information, see
         <xref linkend="backup-archiving-wal"/> and
         <xref linkend="archive-modules"/>.
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