Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhC1k-00A7Wf-R6 for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 17:23:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhC1i-009fGJ-W2 for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 17:22:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhC1i-009fGA-La for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 17:22:59 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rhC1f-002kpb-Nn for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 17:22:58 +0000 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-36540b9885cso13472385ab.1 for ; Mon, 04 Mar 2024 09:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709572974; x=1710177774; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=4/pPV64Vk3VkMgjhhliyXpLVQVAG7raJDlbZdXBmb6c=; b=FX4FqgWpntDJDBAHzA8UsF+ema6G73EsRQclmRcQSKl/mOtqMObjBrYD8ZmlAxtWfQ 4h5mABF3uG0EJhuw3aR+oECV+tX8TrmdaYaXbUypvbOUlQ4XAyu0kaoy/98mksxJSbRg 5rAp0I6zxSFqXCrRL/EiHZ0BfmM2HisPI/rzOVvDweD7ETZHlZryqDphOIV5Q94j7qM+ gIugpS3atNJ4B7i1AqpyGwenkdU/nplvHLvu9pOBsVfDriinBGLUUDliUzH6l7KyP9bg z2yCYuUms0+soKiuMZSQHJT5lcQZJaw4wp8OcnsFfWe8PoAIDVlTyH8GD1mCodqA6sMH l/RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709572974; x=1710177774; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4/pPV64Vk3VkMgjhhliyXpLVQVAG7raJDlbZdXBmb6c=; b=vP8MHe6zVda300yxGk9X+YBVZGFsQ9BkC9Ieoqzrsf8BmQq/swJ3qybnVUc2/+m6kH 9mquo2p+ciTju9kRyw/xZJKQWMUTRuUfs2Hj7oKZMuqCTsKeRKyHg8VmRnNtf1LClR1V ydvhGSn9RyuYaKQ+tAH0NY63K2sw+aIYKXs1q9lrhC8PCEX9bEBa1vJB+GWml7L1W/OM hakwhMOS2JuMHn/l2TAn7j3qyMnENcNVgnSGs/zO+i3yWcqieSTKiCYBo7rDw/KdJkyg lK9leriGxsyeRaklB1Wuy3K06PTNov+5TtY9QChJTt2YwB6pDxP0NCsGoBzht2lrMNh+ rEOg== X-Forwarded-Encrypted: i=1; AJvYcCXM1r5cJGRL86TLQyy3+l/NFSNtbXsYEV5mSc5bqbJStSnPTWhMWfMNAs+WuwUnbU94449lK7HvzfuB7vI4WE7WGFLG5nzz8OOMDklMXMf6h3Ye X-Gm-Message-State: AOJu0YyzohqKbj55VkfCAPx7+corhiq31gq8zJkKroSLeHDAGPgPajk/ xj3+UIT0fsUhz97GvejR2rQwyx9tDCC+PnJVCJkCygtFo2cpeYez X-Google-Smtp-Source: AGHT+IGTFKAMB1d2qXGNBSQfCc76pJ3W2eKe4+oDgSGAJ1XXsLe29eJceEFtZbQpgQk3lctlSDDJ4A== X-Received: by 2002:a05:6e02:1d05:b0:364:ff89:97c1 with SMTP id i5-20020a056e021d0500b00364ff8997c1mr138744ila.9.1709572974042; Mon, 04 Mar 2024 09:22:54 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id l3-20020a056e020dc300b0036287013d01sm2633111ilj.36.2024.03.04.09.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 09:22:53 -0800 (PST) Date: Mon, 4 Mar 2024 11:22:52 -0600 From: Nathan Bossart To: Daniel Gustafsson Cc: bt23nguyent , Alvaro Herrera , pgsql-hackers@lists.postgresql.org Subject: Re: Improve the log message output of basic_archive when basic_archive.archive_directory parameter is not set Message-ID: <20240304172252.GA3161951@nathanxps13> References: <20230915143827.GA1912920@nathanxps13> <85b9e69997bbd5d8302a3a99a2de246d@oss.nttdata.com> <18cbd8ca6f5390cda2920644f891a419@oss.nttdata.com> <20230925222047.GA3173226@nathanxps13> <482056B1-D930-417C-9473-CB1A045E42AE@yesql.se> <20231013022559.GA1266364@nathanxps13> <20240105230357.GA2425960@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Mar 04, 2024 at 03:21:59PM +0100, Daniel Gustafsson wrote: > Looking at this again I think this is about ready to go in. My only comment is > that doc/src/sgml/archive-modules.sgml probably should be updated to refer to > setting the errdetail, especially since we document the errormessage there. Thanks for reviewing. How does this look? -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --LQksG6bCIzRHxTLp Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="v5-0001-Add-macro-for-customizing-an-archive-module-WARNI.patch" Content-Transfer-Encoding: 8bit From 437e4fa9ec27ecf870530fc579cd7673dfcf96af Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Mon, 4 Mar 2024 11:15:37 -0600 Subject: [PATCH v5 1/1] Add macro for customizing an archive module WARNING message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Presently, if an archive module's check_configured_cb callback returns false, a generic WARNING about the archive module misconfiguration is emitted, which unfortunately provides no actionable details about the source of the miconfiguration. This commit introduces a macro that archive module authors can use to add a DETAIL line to this WARNING. Co-authored-by: Tung Nguyen Reviewed-by: Daniel Gustafsson, Álvaro Herrera Discussion: https://postgr.es/m/4109578306242a7cd5661171647e11b2%40oss.nttdata.com --- contrib/basic_archive/basic_archive.c | 7 ++++++- doc/src/sgml/archive-modules.sgml | 12 ++++++++++++ src/backend/archive/shell_archive.c | 7 ++++++- src/backend/postmaster/pgarch.c | 8 +++++++- src/include/archive/archive_module.h | 8 ++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c index 804567e919..6b102e9072 100644 --- a/contrib/basic_archive/basic_archive.c +++ b/contrib/basic_archive/basic_archive.c @@ -161,7 +161,12 @@ check_archive_directory(char **newval, void **extra, GucSource source) static bool basic_archive_configured(ArchiveModuleState *state) { - return archive_directory != NULL && archive_directory[0] != '\0'; + if (archive_directory != NULL && archive_directory[0] != '\0') + return true; + + arch_module_check_errdetail("%s is not set.", + "basic_archive.archive_directory"); + return false; } /* diff --git a/doc/src/sgml/archive-modules.sgml b/doc/src/sgml/archive-modules.sgml index 7064307d9e..cf7438a759 100644 --- a/doc/src/sgml/archive-modules.sgml +++ b/doc/src/sgml/archive-modules.sgml @@ -114,6 +114,18 @@ WARNING: archive_mode enabled, yet archiving is not configured In the latter case, the server will periodically call this function, and archiving will proceed only when it returns true. + + + + When returning false, it may be useful to append some + additional information to the generic warning message. To do that, provide + a message to the arch_module_check_errdetail macro + before returning false. Like + errdetail(), this macro accepts a format string + followed by an optional list of arguments. The resulting string will be + emitted as the DETAIL line of the warning message. + + diff --git a/src/backend/archive/shell_archive.c b/src/backend/archive/shell_archive.c index c95b732495..bff0ab800d 100644 --- a/src/backend/archive/shell_archive.c +++ b/src/backend/archive/shell_archive.c @@ -45,7 +45,12 @@ shell_archive_init(void) static bool shell_archive_configured(ArchiveModuleState *state) { - return XLogArchiveCommand[0] != '\0'; + if (XLogArchiveCommand[0] != '\0') + return true; + + arch_module_check_errdetail("%s is not set.", + "archive_command"); + return false; } static bool diff --git a/src/backend/postmaster/pgarch.c b/src/backend/postmaster/pgarch.c index bb0eb13a89..f97035ca03 100644 --- a/src/backend/postmaster/pgarch.c +++ b/src/backend/postmaster/pgarch.c @@ -88,6 +88,7 @@ typedef struct PgArchData } PgArchData; char *XLogArchiveLibrary = ""; +char *arch_module_check_errdetail_string; /* ---------- @@ -401,12 +402,17 @@ pgarch_ArchiverCopyLoop(void) */ HandlePgArchInterrupts(); + /* Reset variables that might be set by the callback */ + arch_module_check_errdetail_string = NULL; + /* can't do anything if not configured ... */ if (ArchiveCallbacks->check_configured_cb != NULL && !ArchiveCallbacks->check_configured_cb(archive_module_state)) { ereport(WARNING, - (errmsg("archive_mode enabled, yet archiving is not configured"))); + (errmsg("archive_mode enabled, yet archiving is not configured"), + arch_module_check_errdetail_string ? + errdetail_internal("%s", arch_module_check_errdetail_string) : 0)); return; } diff --git a/src/include/archive/archive_module.h b/src/include/archive/archive_module.h index fd59b9faf4..763af76e54 100644 --- a/src/include/archive/archive_module.h +++ b/src/include/archive/archive_module.h @@ -56,4 +56,12 @@ typedef const ArchiveModuleCallbacks *(*ArchiveModuleInit) (void); extern PGDLLEXPORT const ArchiveModuleCallbacks *_PG_archive_module_init(void); +/* Support for messages reported from archive module callbacks. */ + +extern PGDLLIMPORT char *arch_module_check_errdetail_string; + +#define arch_module_check_errdetail \ + pre_format_elog_string(errno, TEXTDOMAIN), \ + arch_module_check_errdetail_string = format_elog_string + #endif /* _ARCHIVE_MODULE_H */ -- 2.25.1 --LQksG6bCIzRHxTLp--