Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYarF-0002HL-Ld for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Sep 2022 22:27:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oYarD-0005rj-Kv for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Sep 2022 22:27:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYarD-0005qF-1m for pgsql-hackers@lists.postgresql.org; Wed, 14 Sep 2022 22:27:47 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oYar7-0002yq-96 for pgsql-hackers@postgresql.org; Wed, 14 Sep 2022 22:27:44 +0000 Received: by mail-pl1-x62b.google.com with SMTP id jm11so16489039plb.13 for ; Wed, 14 Sep 2022 15:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=ZCKOXsXip3t/jVELUvMauOQ4TJ57y4UkiHdeKp7GziA=; b=VAz6DfqN5i/9eoLKLX+nZgpocxXWM4x6FSxJskqkDVssDbUvU0+Yik1mkvw9FahHSp CbZGDvRmOfO6KRv2KtVje6moTcuLB3lvi8rPzXwcMCLjs2PM1kW7NVZaZk8w6wnJL9sZ QB7T44d/RpJ64XM+cRuk0qaGTqbZ+FC+LYVIFRQBxuKyru1UGGd6vuczqTa91YsHDEsW tI7z71KnCPqxyfJe5ApmFX8U8OQAJROdjugz66Albtz9Y3LCm6Bi2nhL0xAQ5BRGL0SW UfTbuMQMeRGPvTBp/i5R7iGYGRyexyGfwlfLjpNzhRg7mdsviK9PmqNOfF0U6XBqx41D IB3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=ZCKOXsXip3t/jVELUvMauOQ4TJ57y4UkiHdeKp7GziA=; b=vZChE2RvT2nf97hYD+LI/uohnOPgXu/dP7sWVTe8MKcEuI7D9VoQMyuClpFcj5VN8V P75p9Y/BK3kb4+B7zRx37ocagaCaV7pUBl4ei/lSKBT8x4Mkic3X4ONrCqRVA+STILKI EX/j5ZzlclZIdNgF+y+tMG4Fy1EwyexqICT13IRlItRmsCYFLvb8/Qzn+xNRCGl0gNLW 399oaLQPuIr0qfsicr2QV51IblFVYn9Cl5qbSR+bhHL2dPeyslE8de8Gf4IU9pv9TfE4 H1BZFs8w7bsFt8O08Pus+u7pqBYpfsvzvoPYQIQuaNHwXe1/aZIYL79n/Eec60EZeRLC aiFg== X-Gm-Message-State: ACrzQf1YvGHdVWowwgA7MQeB5QywQVVFMV2gutBQglsrq/gE0HqOz5iL Ulh4G4ex3d1dvV8/CAEaLJI= X-Google-Smtp-Source: AMsMyM4MDyOmD+Ox8wuBNE661MJOmubCY3hvlbrZrcBZxWK7/x0pc6gajOTwGcNXzhoW1m63EXtq+g== X-Received: by 2002:a17:902:ed82:b0:178:5653:ecfb with SMTP id e2-20020a170902ed8200b001785653ecfbmr1192220plj.58.1663194459678; Wed, 14 Sep 2022 15:27:39 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id 32-20020a631360000000b0042bf6034b3fsm10294905pgt.55.2022.09.14.15.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 15:27:38 -0700 (PDT) Date: Wed, 14 Sep 2022 15:27:36 -0700 From: Nathan Bossart To: Tom Lane Cc: Peter Eisentraut , Benoit =?iso-8859-1?Q?Lobr=E9au?= , Alvaro Herrera , Robert Haas , "Bossart, Nathan" , David Steele , Fujii Masao , "pgsql-hackers@postgresql.org" , Michael Paquier , Magnus Hagander , Stephen Frost Subject: Re: archive modules Message-ID: <20220914222736.GA3042279@nathanxps13> References: <20220830163048.GA544233@nathanxps13> <613541.1662842656@sss.pgh.pa.us> <20220910211046.GA2651323@nathanxps13> <9ee5d180-2c32-a1ca-d3d7-63a723f68d9a@enterprisedb.com> <20220914200305.GA2984249@nathanxps13> <37857474-5caa-ccb3-92a3-150ddfe851ab@enterprisedb.com> <2884265.1663188443@sss.pgh.pa.us> <20220914211746.GA2986134@nathanxps13> <2910705.1663193529@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="fdj2RfSjLxBAspz7" Content-Disposition: inline In-Reply-To: <2910705.1663193529@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --fdj2RfSjLxBAspz7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 14, 2022 at 06:12:09PM -0400, Tom Lane wrote: > Nathan Bossart writes: >> On Wed, Sep 14, 2022 at 04:47:23PM -0400, Tom Lane wrote: >>> Yeah, the objection there is only to trying to enforce such >>> interrelationships in GUC hooks. In this case it seems to me that >>> we could easily check and complain at the point where we're about >>> to use the GUC values. > >> I think the cleanest way to do something like that would be to load a >> check_configured_cb that produces a WARNING. IIRC failing in >> LoadArchiveLibrary() would just cause the archiver process to restart over >> and over. HandlePgArchInterrupts() might need some work as well. > > Hm. Maybe consistency-check these settings in the postmaster, sometime > after we've absorbed all GUC settings but before we launch any children? > That could provide a saner implementation for the recovery_target_* > variables too. Both archive_command and archive_library are PGC_SIGHUP, so IIUC that wouldn't be sufficient. I attached a quick sketch that seems to provide the desired behavior. It's nowhere near committable yet, but it demonstrates what I'm thinking. For recovery_target_*, something like you are describing seems reasonable. I believe PostmasterMain() already performs some similar checks. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --fdj2RfSjLxBAspz7 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="handle_archive_misconfiguration.patch" diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index 6ce361707d..1d0c6029a5 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -422,8 +422,15 @@ pgarch_ArchiverCopyLoop(void) HandlePgArchInterrupts(); /* can't do anything if not configured ... */ - if (ArchiveContext.check_configured_cb != NULL && - !ArchiveContext.check_configured_cb()) + if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0') + { + ereport(WARNING, + (errmsg("archive_mode enabled, but archiving is misconfigured"), + errdetail("Only one of archive_command, archive_library may be set."))); + return; + } + else if (ArchiveContext.check_configured_cb != NULL && + !ArchiveContext.check_configured_cb()) { ereport(WARNING, (errmsg("archive_mode enabled, yet archiving is not configured"))); @@ -794,6 +801,9 @@ HandlePgArchInterrupts(void) { char *archiveLib = pstrdup(XLogArchiveLibrary); bool archiveLibChanged; + bool misconfiguredBeforeReload = (XLogArchiveCommand[0] != '\0' && + XLogArchiveLibrary[0] != '\0'); + bool misconfiguredAfterReload; ConfigReloadPending = false; ProcessConfigFile(PGC_SIGHUP); @@ -801,7 +811,11 @@ HandlePgArchInterrupts(void) archiveLibChanged = strcmp(XLogArchiveLibrary, archiveLib) != 0; pfree(archiveLib); - if (archiveLibChanged) + misconfiguredAfterReload = (XLogArchiveCommand[0] != '\0' && + XLogArchiveLibrary[0] != '\0'); + + if ((archiveLibChanged && !misconfiguredAfterReload) || + misconfiguredBeforeReload != misconfiguredAfterReload) { /* * Call the currently loaded archive module's shutdown callback, @@ -816,10 +830,17 @@ HandlePgArchInterrupts(void) * internal_load_library()). To deal with this, we simply restart * the archiver. The new archive module will be loaded when the * new archiver process starts up. + * + * Similarly, we restart the archiver if our misconfiguration status + * changes. If the parameters were misconfigured but are no longer, + * we must restart to load the correct callbacks. If the parameters + * weren't misconfigured but now are, we must restart to unload the + * current callbacks. */ ereport(LOG, (errmsg("restarting archiver process because value of " - "\"archive_library\" was changed"))); + "\"archive_library\" or \"archive_command\" was " + "changed"))); proc_exit(0); } @@ -838,6 +859,14 @@ LoadArchiveLibrary(void) memset(&ArchiveContext, 0, sizeof(ArchiveModuleCallbacks)); + /* + * If both a shell command and an archive library are specified, it is not + * clear what we should do, so do nothing. The archiver will emit WARNINGs + * about the misconfiguration. + */ + if (XLogArchiveLibrary[0] != '\0' && XLogArchiveCommand[0] != '\0') + return; + /* * If shell archiving is enabled, use our special initialization function. * Otherwise, load the library and call its _PG_archive_module_init(). --fdj2RfSjLxBAspz7--