Skip to content

Commit 2c29e7f

Browse files
Add macro for customizing an archiving WARNING message.
Presently, if an archive module's check_configured_cb callback returns false, a generic WARNING message is emitted, which unfortunately provides no actionable details about the reason why the module is not configured. This commit introduces a macro that archive module authors can use to add a DETAIL line to this WARNING message. Co-authored-by: Tung Nguyen Reviewed-by: Daniel Gustafsson, Álvaro Herrera Discussion: https://postgr.es/m/4109578306242a7cd5661171647e11b2%40oss.nttdata.com
1 parent e5bc945 commit 2c29e7f

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

contrib/basic_archive/basic_archive.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ check_archive_directory(char **newval, void **extra, GucSource source)
161161
static bool
162162
basic_archive_configured(ArchiveModuleState *state)
163163
{
164-
return archive_directory != NULL && archive_directory[0] != '\0';
164+
if (archive_directory != NULL && archive_directory[0] != '\0')
165+
return true;
166+
167+
arch_module_check_errdetail("%s is not set.",
168+
"basic_archive.archive_directory");
169+
return false;
165170
}
166171

167172
/*

doc/src/sgml/archive-modules.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ WARNING: archive_mode enabled, yet archiving is not configured
114114
In the latter case, the server will periodically call this function, and
115115
archiving will proceed only when it returns <literal>true</literal>.
116116
</para>
117+
118+
<note>
119+
<para>
120+
When returning <literal>false</literal>, it may be useful to append some
121+
additional information to the generic warning message. To do that, provide
122+
a message to the <function>arch_module_check_errdetail</function> macro
123+
before returning <literal>false</literal>. Like
124+
<function>errdetail()</function>, this macro accepts a format string
125+
followed by an optional list of arguments. The resulting string will be
126+
emitted as the <literal>DETAIL</literal> line of the warning message.
127+
</para>
128+
</note>
117129
</sect2>
118130

119131
<sect2 id="archive-module-archive">

src/backend/archive/shell_archive.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ shell_archive_init(void)
4545
static bool
4646
shell_archive_configured(ArchiveModuleState *state)
4747
{
48-
return XLogArchiveCommand[0] != '\0';
48+
if (XLogArchiveCommand[0] != '\0')
49+
return true;
50+
51+
arch_module_check_errdetail("%s is not set.",
52+
"archive_command");
53+
return false;
4954
}
5055

5156
static bool

src/backend/postmaster/pgarch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct PgArchData
8888
} PgArchData;
8989

9090
char *XLogArchiveLibrary = "";
91+
char *arch_module_check_errdetail_string;
9192

9293

9394
/* ----------
@@ -401,12 +402,17 @@ pgarch_ArchiverCopyLoop(void)
401402
*/
402403
HandlePgArchInterrupts();
403404

405+
/* Reset variables that might be set by the callback */
406+
arch_module_check_errdetail_string = NULL;
407+
404408
/* can't do anything if not configured ... */
405409
if (ArchiveCallbacks->check_configured_cb != NULL &&
406410
!ArchiveCallbacks->check_configured_cb(archive_module_state))
407411
{
408412
ereport(WARNING,
409-
(errmsg("archive_mode enabled, yet archiving is not configured")));
413+
(errmsg("archive_mode enabled, yet archiving is not configured"),
414+
arch_module_check_errdetail_string ?
415+
errdetail_internal("%s", arch_module_check_errdetail_string) : 0));
410416
return;
411417
}
412418

src/include/archive/archive_module.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,12 @@ typedef const ArchiveModuleCallbacks *(*ArchiveModuleInit) (void);
5656

5757
extern PGDLLEXPORT const ArchiveModuleCallbacks *_PG_archive_module_init(void);
5858

59+
/* Support for messages reported from archive module callbacks. */
60+
61+
extern PGDLLIMPORT char *arch_module_check_errdetail_string;
62+
63+
#define arch_module_check_errdetail \
64+
pre_format_elog_string(errno, TEXTDOMAIN), \
65+
arch_module_check_errdetail_string = format_elog_string
66+
5967
#endif /* _ARCHIVE_MODULE_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy