summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@kurilemu.de>2025-09-26 15:21:49 +0200
committerÁlvaro Herrera <alvherre@kurilemu.de>2025-09-26 15:21:49 +0200
commitdbf8cfb4f02eb9ec5525de1761675f9babfd30e3 (patch)
tree7bb306ce314cf262c6bb54473bc7571d9cab1d4b /src
parent8bb174295e8920fe202e2fb4c8d271e4546b9e98 (diff)
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. To keep the strings translatable, the relevant makefile now also scans src/include for this specific file. I didn't want to have it scan all .h files, as then gettext would have to scan all header files. I didn't find any way to affect the meson behavior in this respect though. Author: Álvaro Herrera <alvherre@kurilemu.de> Co-authored-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com> Discussion: https://postgr.es/m/202507151830.dwgz5nmmqtdy@alvherre.pgsql
Diffstat (limited to 'src')
-rw-r--r--src/backend/nls.mk2
-rw-r--r--src/backend/postmaster/launch_backend.c32
-rw-r--r--src/backend/utils/init/miscinit.c59
-rw-r--r--src/include/postmaster/proctypelist.h51
-rwxr-xr-xsrc/tools/pginclude/headerscheck9
5 files changed, 65 insertions, 88 deletions
diff --git a/src/backend/nls.mk b/src/backend/nls.mk
index b7d5dd46e45..698b1083f4b 100644
--- a/src/backend/nls.mk
+++ b/src/backend/nls.mk
@@ -28,7 +28,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 $(srcdir)/../include/ \( -name '*.c' -o -name "proctypelist.h" \) -print | LC_ALL=C sort >$@
my-clean:
rm -f gettext-files
diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c
index 79708e59259..976638a58ac 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -179,34 +179,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/proctypelist.h"
+#undef PG_PROCTYPE
};
const char *
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 545d1e90fbd..fec79992c8d 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 = description; break;
+#include "postmaster/proctypelist.h"
+#undef PG_PROCTYPE
}
-
return backendDesc;
}
diff --git a/src/include/postmaster/proctypelist.h b/src/include/postmaster/proctypelist.h
new file mode 100644
index 00000000000..242862451d8
--- /dev/null
+++ b/src/include/postmaster/proctypelist.h
@@ -0,0 +1,51 @@
+/*-------------------------------------------------------------------------
+ *
+ * proctypelist.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/proctypelist.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/* there is deliberately not an #ifndef PROCTYPELIST_H here */
+
+/*
+ * 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.
+ */
+
+/*
+ * List of process types (symbol, description, Main function, shmem_attach)
+ * entries.
+ */
+
+
+/* bktype, description, main_func, shmem_attach */
+PG_PROCTYPE(B_ARCHIVER, gettext_noop("archiver"), PgArchiverMain, true)
+PG_PROCTYPE(B_AUTOVAC_LAUNCHER, gettext_noop("autovacuum launcher"), AutoVacLauncherMain, true)
+PG_PROCTYPE(B_AUTOVAC_WORKER, gettext_noop("autovacuum worker"), AutoVacWorkerMain, true)
+PG_PROCTYPE(B_BACKEND, gettext_noop("client backend"), BackendMain, true)
+PG_PROCTYPE(B_BG_WORKER, gettext_noop("background worker"), BackgroundWorkerMain, true)
+PG_PROCTYPE(B_BG_WRITER, gettext_noop("background writer"), BackgroundWriterMain, true)
+PG_PROCTYPE(B_CHECKPOINTER, gettext_noop("checkpointer"), CheckpointerMain, true)
+PG_PROCTYPE(B_DEAD_END_BACKEND, gettext_noop("dead-end client backend"), BackendMain, true)
+PG_PROCTYPE(B_INVALID, gettext_noop("unrecognized"), NULL, false)
+PG_PROCTYPE(B_IO_WORKER, gettext_noop("io worker"), IoWorkerMain, true)
+PG_PROCTYPE(B_LOGGER, gettext_noop("syslogger"), SysLoggerMain, false)
+PG_PROCTYPE(B_SLOTSYNC_WORKER, gettext_noop("slotsync worker"), ReplSlotSyncWorkerMain, true)
+PG_PROCTYPE(B_STANDALONE_BACKEND, gettext_noop("standalone backend"), NULL, false)
+PG_PROCTYPE(B_STARTUP, gettext_noop("startup"), StartupProcessMain, true)
+PG_PROCTYPE(B_WAL_RECEIVER, gettext_noop("walreceiver"), WalReceiverMain, true)
+PG_PROCTYPE(B_WAL_SENDER, gettext_noop("walsender"), NULL, true)
+PG_PROCTYPE(B_WAL_SUMMARIZER, gettext_noop("walsummarizer"), WalSummarizerMain, true)
+PG_PROCTYPE(B_WAL_WRITER, gettext_noop("walwriter"), WalWriterMain, true)
diff --git a/src/tools/pginclude/headerscheck b/src/tools/pginclude/headerscheck
index d017490a538..a52a5580bdc 100755
--- a/src/tools/pginclude/headerscheck
+++ b/src/tools/pginclude/headerscheck
@@ -126,13 +126,14 @@ do
# they contain lists that might have multiple use-cases.
test "$f" = src/include/access/rmgrlist.h && continue
test "$f" = src/include/parser/kwlist.h && continue
- test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue
- test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue
- test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
- test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
+ test "$f" = src/include/postmaster/proctypelist.h && continue
test "$f" = src/include/regex/regerrs.h && continue
test "$f" = src/include/storage/lwlocklist.h && continue
test "$f" = src/include/tcop/cmdtaglist.h && continue
+ test "$f" = src/interfaces/ecpg/preproc/c_kwlist.h && continue
+ test "$f" = src/interfaces/ecpg/preproc/ecpg_kwlist.h && continue
+ test "$f" = src/pl/plpgsql/src/pl_reserved_kwlist.h && continue
+ test "$f" = src/pl/plpgsql/src/pl_unreserved_kwlist.h && continue
test "$f" = src/pl/plpgsql/src/plerrcodes.h && continue
test "$f" = src/pl/plpython/spiexceptions.h && continue
test "$f" = src/pl/tcl/pltclerrcodes.h && continue