v3-0001-Create-a-separate-file-listing-backend-types.patch
text/x-patch
Filename: v3-0001-Create-a-separate-file-listing-backend-types.patch
Type: text/x-patch
Part: 0
Message:
Re: refactor backend type lists
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0001
Subject: Create a separate file listing backend types
| File | + | − |
|---|---|---|
| src/backend/postmaster/launch_backend.c | 4 | 28 |
| src/backend/utils/init/miscinit.c | 4 | 55 |
| src/include/postmaster/proctypelist.h | 50 | 0 |
From 896a377a33a6e8035f39e3ccfbef8156cab51235 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81lvaro=20Herrera?= <alvherre@kurilemu.de>
Date: Tue, 15 Jul 2025 18:19:27 +0200
Subject: [PATCH 1/3] 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.
Signed-off-by: Jonathan Gonzalez V. <jonathan.abdiel@gmail.com>
---
src/backend/postmaster/launch_backend.c | 32 ++------------
src/backend/utils/init/miscinit.c | 59 ++-----------------------
src/include/postmaster/proctypelist.h | 50 +++++++++++++++++++++
3 files changed, 58 insertions(+), 83 deletions(-)
create mode 100644 src/include/postmaster/proctypelist.h
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..749fb502e95 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/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..919f00bb3a7
--- /dev/null
+++ b/src/include/postmaster/proctypelist.h
@@ -0,0 +1,50 @@
+/*-------------------------------------------------------------------------
+ *
+ * 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, "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, "unrecognized", 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.48.1