Hello We have lists of backend types scattered through the tree. I found two current ones, and Euler Taveira wants to add a couple more[1]. His patch is actually blocked on not adding more, so this seems worth doing. Bikeshedding welcome (for a limited time).
[1] https://postgr.es/m/313aa202-b5fa-4e3f-95d0-83425575c...@app.fastmail.com A couple points. First, launch_backend.c has its own strings for process names, inconsistent with the ones in miscinit.c. I think we should ignore the ones in launch_backend.c, because they're less polished and not used for anything interesting, whereas the ones in miscinit.c::GetBackendTypeDesc() are -- particularly init_ps_display and pg_stat_activity. Second, in discussion [2] leading to commit 18d67a8d7d30 (Nov 2024) it was agreed to add support for translating backend type descriptions. I'm not really sure that this is useful. It would be, if set_ps_display and pg_stat_activity used translated names, so that you could match what log messages say with what the process lists show. But I think we've historically not translated those. We have a few translatable strings as the argument of HandleChildCrash() in postmaster.c, but those are using names that are yet a third source of strings; I'm not a fan of this. (For staters, if a translation decided to use non-ascii chars for process names, would that work okay in set_ps_display? I bet it wouldn't, because that's using strlen()). So I would propose to rewind a bit here, and remove translation from all those places so that the output is consistent (== usable) between log messages and ps/pg_stat_activity. [2] https://www.postgresql.org/message-id/flat/a102f15f-eac4-4ff2-af02-f9ff209ec66f%40iki.fi Third, I didn't do it here, but HandleChildCrash is currently called like HandleChildCrash(pid, exitstatus, _("WAL writer process")); creating yet another source of strings to describe process types. I think it would be much better to avoid that by using HandleChildCrash(pid, exitstatus, _(GetBackendTypeDesc(B_WAL_WRITER)); instead. If we decide to get rid of the translation, then HandleChildCrash(pid, exitstatus, GetBackendTypeDesc(B_WAL_WRITER); This last one would be my preference actually. Note that we use this string in an error that looks like this (LogChildExit): /*------ translator: %s is a noun phrase describing a child process, such as "server process" */ (errmsg("%s (PID %d) exited with exit code %d", procname, pid, WEXITSTATUS(exitstatus)), I would change this to errmsg("process %d of type \"%s\" exited with exit code %d", pid, procname, WEXITSTATUS()) Note that in the original, the process name is translated, and in my proposal it wouldn't be. (This helps match the log message with "ps" and pg_stat_activity). Fourth: patch 0002 is a necessary hack to get the proctype_list.h strings be picked up for translation by gettext in makefiles. It's quite ugly! I'd rather not have it at all. I have no idea how to do this in Meson. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "I dream about dreams about dreams", sang the nightingale under the pale moon (Sandman)
>From 1165efd15dbc73093eb16fffc05047a8455ecb5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvhe...@kurilemu.de> Date: Tue, 15 Jul 2025 18:19:27 +0200 Subject: [PATCH 1/2] Create a separate file listing backend types Use our established coding pattern to reduce maintenance pain when adding other per-process-type characteristics. Like PG_KEYWORD, PG_CMDTAG, PG_RMGR. --- src/backend/postmaster/launch_backend.c | 32 ++------------ src/backend/utils/init/miscinit.c | 59 ++----------------------- src/include/postmaster/proctype_list.h | 44 ++++++++++++++++++ 3 files changed, 52 insertions(+), 83 deletions(-) create mode 100644 src/include/postmaster/proctype_list.h diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index bf6b55ee830..d8ac514bbbc 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -177,34 +177,10 @@ typedef struct } child_process_kind; static child_process_kind child_process_kinds[] = { - [B_INVALID] = {"invalid", NULL, false}, - - [B_BACKEND] = {"backend", BackendMain, true}, - [B_DEAD_END_BACKEND] = {"dead-end backend", BackendMain, true}, - [B_AUTOVAC_LAUNCHER] = {"autovacuum launcher", AutoVacLauncherMain, true}, - [B_AUTOVAC_WORKER] = {"autovacuum worker", AutoVacWorkerMain, true}, - [B_BG_WORKER] = {"bgworker", BackgroundWorkerMain, true}, - - /* - * WAL senders start their life as regular backend processes, and change - * their type after authenticating the client for replication. We list it - * here for PostmasterChildName() but cannot launch them directly. - */ - [B_WAL_SENDER] = {"wal sender", NULL, true}, - [B_SLOTSYNC_WORKER] = {"slot sync worker", ReplSlotSyncWorkerMain, true}, - - [B_STANDALONE_BACKEND] = {"standalone backend", NULL, false}, - - [B_ARCHIVER] = {"archiver", PgArchiverMain, true}, - [B_BG_WRITER] = {"bgwriter", BackgroundWriterMain, true}, - [B_CHECKPOINTER] = {"checkpointer", CheckpointerMain, true}, - [B_IO_WORKER] = {"io_worker", IoWorkerMain, true}, - [B_STARTUP] = {"startup", StartupProcessMain, true}, - [B_WAL_RECEIVER] = {"wal_receiver", WalReceiverMain, true}, - [B_WAL_SUMMARIZER] = {"wal_summarizer", WalSummarizerMain, true}, - [B_WAL_WRITER] = {"wal_writer", WalWriterMain, true}, - - [B_LOGGER] = {"syslogger", SysLoggerMain, false}, +#define PG_PROCTYPE(bktype, description, main_func, shmem_attach) \ + [bktype] = {description, main_func, shmem_attach}, +#include "postmaster/proctype_list.h" +#undef PG_PROCTYPE }; const char * diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 43b4dbccc3d..53a232cee41 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -266,62 +266,11 @@ GetBackendTypeDesc(BackendType backendType) switch (backendType) { - case B_INVALID: - backendDesc = gettext_noop("not initialized"); - break; - case B_ARCHIVER: - backendDesc = gettext_noop("archiver"); - break; - case B_AUTOVAC_LAUNCHER: - backendDesc = gettext_noop("autovacuum launcher"); - break; - case B_AUTOVAC_WORKER: - backendDesc = gettext_noop("autovacuum worker"); - break; - case B_BACKEND: - backendDesc = gettext_noop("client backend"); - break; - case B_DEAD_END_BACKEND: - backendDesc = gettext_noop("dead-end client backend"); - break; - case B_BG_WORKER: - backendDesc = gettext_noop("background worker"); - break; - case B_BG_WRITER: - backendDesc = gettext_noop("background writer"); - break; - case B_CHECKPOINTER: - backendDesc = gettext_noop("checkpointer"); - break; - case B_IO_WORKER: - backendDesc = gettext_noop("io worker"); - break; - case B_LOGGER: - backendDesc = gettext_noop("logger"); - break; - case B_SLOTSYNC_WORKER: - backendDesc = gettext_noop("slotsync worker"); - break; - case B_STANDALONE_BACKEND: - backendDesc = gettext_noop("standalone backend"); - break; - case B_STARTUP: - backendDesc = gettext_noop("startup"); - break; - case B_WAL_RECEIVER: - backendDesc = gettext_noop("walreceiver"); - break; - case B_WAL_SENDER: - backendDesc = gettext_noop("walsender"); - break; - case B_WAL_SUMMARIZER: - backendDesc = gettext_noop("walsummarizer"); - break; - case B_WAL_WRITER: - backendDesc = gettext_noop("walwriter"); - break; +#define PG_PROCTYPE(bktype, description, main_func, shmem_attach) \ + case bktype: backendDesc = gettext_noop(description); break; +#include "postmaster/proctype_list.h" +#undef PG_PROCTYPE } - return backendDesc; } diff --git a/src/include/postmaster/proctype_list.h b/src/include/postmaster/proctype_list.h new file mode 100644 index 00000000000..749a6db8364 --- /dev/null +++ b/src/include/postmaster/proctype_list.h @@ -0,0 +1,44 @@ +/*------------------------------------------------------------------------- + * + * proctype_list.h + * + * The list of process types is kept on its own source file for use by + * automatic tools. The exact representation of a process type is + * determined by the PG_PROCTYPE macro, which is not defined in this + * file; it can be defined by the caller for special purposes. + * + * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * IDENTIFICATION + * src/include/postmaster/proctype_list.h + * + *------------------------------------------------------------------------- + */ + +/* there is deliberately not an #ifndef PROCTYPE_LIST_H here */ + +/* + * List of process types (symbol, description, Main function, shmem_attach) + * entries. + */ + +/* bktype, description, main_func, shmem_attach */ +PG_PROCTYPE(B_ARCHIVER, "archiver", PgArchiverMain, true) +PG_PROCTYPE(B_AUTOVAC_LAUNCHER, "autovacuum launcher", AutoVacLauncherMain, true) +PG_PROCTYPE(B_AUTOVAC_WORKER, "autovacuum worker", AutoVacWorkerMain, true) +PG_PROCTYPE(B_BACKEND, "client backend", BackendMain, true) +PG_PROCTYPE(B_BG_WORKER, "background worker", BackgroundWorkerMain, true) +PG_PROCTYPE(B_BG_WRITER, "background writer", BackgroundWriterMain, true) +PG_PROCTYPE(B_CHECKPOINTER, "checkpointer", CheckpointerMain, true) +PG_PROCTYPE(B_DEAD_END_BACKEND, "dead-end client backend", BackendMain, true) +PG_PROCTYPE(B_INVALID, "invalid", NULL, false) +PG_PROCTYPE(B_IO_WORKER, "io worker", IoWorkerMain, true) +PG_PROCTYPE(B_LOGGER, "syslogger", SysLoggerMain, false) +PG_PROCTYPE(B_SLOTSYNC_WORKER, "slotsync worker", ReplSlotSyncWorkerMain, true) +PG_PROCTYPE(B_STANDALONE_BACKEND, "standalone backend", NULL, false) +PG_PROCTYPE(B_STARTUP, "startup", StartupProcessMain, true) +PG_PROCTYPE(B_WAL_RECEIVER, "walreceiver", WalReceiverMain, true) +PG_PROCTYPE(B_WAL_SENDER, "walsender", NULL, true) +PG_PROCTYPE(B_WAL_SUMMARIZER, "walsummarizer", WalSummarizerMain, true) +PG_PROCTYPE(B_WAL_WRITER, "walwriter", WalWriterMain, true) -- 2.39.5
>From f60cd8acee00e954a28e0fb9d3a6fe0ab9221ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvhe...@kurilemu.de> Date: Tue, 15 Jul 2025 19:14:00 +0200 Subject: [PATCH 2/2] Translation support for process type descriptions. But do we really want this? --- src/backend/nls.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/nls.mk b/src/backend/nls.mk index b7d5dd46e45..d75aa8bc5ef 100644 --- a/src/backend/nls.mk +++ b/src/backend/nls.mk @@ -16,7 +16,8 @@ GETTEXT_TRIGGERS = $(BACKEND_COMMON_GETTEXT_TRIGGERS) \ ereport_startup_progress \ json_token_error:2 \ json_manifest_parse_failure:2 \ - error_cb:2 + error_cb:2 \ + PG_PROCTYPE:2 GETTEXT_FLAGS = $(BACKEND_COMMON_GETTEXT_FLAGS) \ GUC_check_errmsg:1:c-format \ GUC_check_errdetail:1:c-format \ @@ -28,7 +29,7 @@ GETTEXT_FLAGS = $(BACKEND_COMMON_GETTEXT_FLAGS) \ error_cb:2:c-format gettext-files: generated-parser-sources generated-headers - find $(srcdir) $(srcdir)/../common $(srcdir)/../port -name '*.c' -print | LC_ALL=C sort >$@ + (find $(srcdir) $(srcdir)/../common $(srcdir)/../port -name '*.c' -print ; echo $(srcdir)/"../include/postmaster/backend_types.h" ) | LC_ALL=C sort >$@ my-clean: rm -f gettext-files -- 2.39.5