Disallow setting archive_library and archive_command at the same time

Setting archive_library and archive_command at the same time is now an
error.  Before, archive_library would take precedence over
archive_command.

Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://www.postgresql.org/message-id/20220914222736.GA3042279%40nathanxps13
This commit is contained in:
Peter Eisentraut 2022-11-15 10:03:12 +01:00
parent 8b5262fa0e
commit d627ce3b70
2 changed files with 19 additions and 3 deletions

View File

@ -3597,9 +3597,11 @@ include_dir 'conf.d'
</para> </para>
<para> <para>
This parameter can only be set in the <filename>postgresql.conf</filename> 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_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, an error will be raised.
If <varname>archive_command</varname> is an empty string (the default) while If <varname>archive_command</varname> is an empty string (the default) while
<varname>archive_mode</varname> is enabled (and <varname>archive_library</varname> <varname>archive_mode</varname> is enabled (and <varname>archive_library</varname>
is set to an empty string), WAL archiving is temporarily is set to an empty string), WAL archiving is temporarily
@ -3624,7 +3626,9 @@ include_dir 'conf.d'
<para> <para>
The library to use for archiving completed WAL file segments. If set to The library to use for archiving completed WAL file segments. If set to
an empty string (the default), archiving via shell is enabled, and 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, an error will be raised. Otherwise, the specified
shared library is used for archiving. The WAL archiver process is shared library is used for archiving. The WAL archiver process is
restarted by the postmaster when this parameter changes. For more restarted by the postmaster when this parameter changes. For more
information, see <xref linkend="backup-archiving-wal"/> and information, see <xref linkend="backup-archiving-wal"/> and

View File

@ -792,6 +792,12 @@ HandlePgArchInterrupts(void)
ConfigReloadPending = false; ConfigReloadPending = false;
ProcessConfigFile(PGC_SIGHUP); ProcessConfigFile(PGC_SIGHUP);
if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("both archive_command and archive_library set"),
errdetail("Only one of archive_command, archive_library may be set.")));
archiveLibChanged = strcmp(XLogArchiveLibrary, archiveLib) != 0; archiveLibChanged = strcmp(XLogArchiveLibrary, archiveLib) != 0;
pfree(archiveLib); pfree(archiveLib);
@ -825,6 +831,12 @@ LoadArchiveLibrary(void)
{ {
ArchiveModuleInit archive_init; ArchiveModuleInit archive_init;
if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("both archive_command and archive_library set"),
errdetail("Only one of archive_command, archive_library may be set.")));
memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks)); memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks));
/* /*