Skip to content

Commit 8b74686

Browse files
Álvaro HerreraCommitfest Bot
authored andcommitted
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.
1 parent 37265ca commit 8b74686

File tree

3 files changed

+58
-83
lines changed

3 files changed

+58
-83
lines changed

src/backend/postmaster/launch_backend.c

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,34 +177,10 @@ typedef struct
177177
} child_process_kind;
178178

179179
static child_process_kind child_process_kinds[] = {
180-
[B_INVALID] = {"invalid", NULL, false},
181-
182-
[B_BACKEND] = {"backend", BackendMain, true},
183-
[B_DEAD_END_BACKEND] = {"dead-end backend", BackendMain, true},
184-
[B_AUTOVAC_LAUNCHER] = {"autovacuum launcher", AutoVacLauncherMain, true},
185-
[B_AUTOVAC_WORKER] = {"autovacuum worker", AutoVacWorkerMain, true},
186-
[B_BG_WORKER] = {"bgworker", BackgroundWorkerMain, true},
187-
188-
/*
189-
* WAL senders start their life as regular backend processes, and change
190-
* their type after authenticating the client for replication. We list it
191-
* here for PostmasterChildName() but cannot launch them directly.
192-
*/
193-
[B_WAL_SENDER] = {"wal sender", NULL, true},
194-
[B_SLOTSYNC_WORKER] = {"slot sync worker", ReplSlotSyncWorkerMain, true},
195-
196-
[B_STANDALONE_BACKEND] = {"standalone backend", NULL, false},
197-
198-
[B_ARCHIVER] = {"archiver", PgArchiverMain, true},
199-
[B_BG_WRITER] = {"bgwriter", BackgroundWriterMain, true},
200-
[B_CHECKPOINTER] = {"checkpointer", CheckpointerMain, true},
201-
[B_IO_WORKER] = {"io_worker", IoWorkerMain, true},
202-
[B_STARTUP] = {"startup", StartupProcessMain, true},
203-
[B_WAL_RECEIVER] = {"wal_receiver", WalReceiverMain, true},
204-
[B_WAL_SUMMARIZER] = {"wal_summarizer", WalSummarizerMain, true},
205-
[B_WAL_WRITER] = {"wal_writer", WalWriterMain, true},
206-
207-
[B_LOGGER] = {"syslogger", SysLoggerMain, false},
180+
#define PG_PROCTYPE(bktype, description, main_func, shmem_attach) \
181+
[bktype] = {description, main_func, shmem_attach},
182+
#include "postmaster/proctypelist.h"
183+
#undef PG_PROCTYPE
208184
};
209185

210186
const char *

src/backend/utils/init/miscinit.c

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -266,62 +266,11 @@ GetBackendTypeDesc(BackendType backendType)
266266

267267
switch (backendType)
268268
{
269-
case B_INVALID:
270-
backendDesc = gettext_noop("not initialized");
271-
break;
272-
case B_ARCHIVER:
273-
backendDesc = gettext_noop("archiver");
274-
break;
275-
case B_AUTOVAC_LAUNCHER:
276-
backendDesc = gettext_noop("autovacuum launcher");
277-
break;
278-
case B_AUTOVAC_WORKER:
279-
backendDesc = gettext_noop("autovacuum worker");
280-
break;
281-
case B_BACKEND:
282-
backendDesc = gettext_noop("client backend");
283-
break;
284-
case B_DEAD_END_BACKEND:
285-
backendDesc = gettext_noop("dead-end client backend");
286-
break;
287-
case B_BG_WORKER:
288-
backendDesc = gettext_noop("background worker");
289-
break;
290-
case B_BG_WRITER:
291-
backendDesc = gettext_noop("background writer");
292-
break;
293-
case B_CHECKPOINTER:
294-
backendDesc = gettext_noop("checkpointer");
295-
break;
296-
case B_IO_WORKER:
297-
backendDesc = gettext_noop("io worker");
298-
break;
299-
case B_LOGGER:
300-
backendDesc = gettext_noop("logger");
301-
break;
302-
case B_SLOTSYNC_WORKER:
303-
backendDesc = gettext_noop("slotsync worker");
304-
break;
305-
case B_STANDALONE_BACKEND:
306-
backendDesc = gettext_noop("standalone backend");
307-
break;
308-
case B_STARTUP:
309-
backendDesc = gettext_noop("startup");
310-
break;
311-
case B_WAL_RECEIVER:
312-
backendDesc = gettext_noop("walreceiver");
313-
break;
314-
case B_WAL_SENDER:
315-
backendDesc = gettext_noop("walsender");
316-
break;
317-
case B_WAL_SUMMARIZER:
318-
backendDesc = gettext_noop("walsummarizer");
319-
break;
320-
case B_WAL_WRITER:
321-
backendDesc = gettext_noop("walwriter");
322-
break;
269+
#define PG_PROCTYPE(bktype, description, main_func, shmem_attach) \
270+
case bktype: backendDesc = gettext_noop(description); break;
271+
#include "postmaster/proctypelist.h"
272+
#undef PG_PROCTYPE
323273
}
324-
325274
return backendDesc;
326275
}
327276

src/include/postmaster/proctypelist.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* proctypelist.h
4+
*
5+
* The list of process types is kept on its own source file for use by
6+
* automatic tools. The exact representation of a process type is
7+
* determined by the PG_PROCTYPE macro, which is not defined in this
8+
* file; it can be defined by the caller for special purposes.
9+
*
10+
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
11+
* Portions Copyright (c) 1994, Regents of the University of California
12+
*
13+
* IDENTIFICATION
14+
* src/include/postmaster/proctypelist.h
15+
*
16+
*-------------------------------------------------------------------------
17+
*/
18+
19+
/* there is deliberately not an #ifndef PROCTYPELIST_H here */
20+
21+
/*
22+
* WAL senders start their life as regular backend processes, and change their
23+
* type after authenticating the client for replication. We list it here for
24+
* PostmasterChildName() but cannot launch them directly.
25+
*/
26+
27+
/*
28+
* List of process types (symbol, description, Main function, shmem_attach)
29+
* entries.
30+
*/
31+
32+
/* bktype, description, main_func, shmem_attach */
33+
PG_PROCTYPE(B_ARCHIVER, "archiver", PgArchiverMain, true)
34+
PG_PROCTYPE(B_AUTOVAC_LAUNCHER, "autovacuum launcher", AutoVacLauncherMain, true)
35+
PG_PROCTYPE(B_AUTOVAC_WORKER, "autovacuum worker", AutoVacWorkerMain, true)
36+
PG_PROCTYPE(B_BACKEND, "client backend", BackendMain, true)
37+
PG_PROCTYPE(B_BG_WORKER, "background worker", BackgroundWorkerMain, true)
38+
PG_PROCTYPE(B_BG_WRITER, "background writer", BackgroundWriterMain, true)
39+
PG_PROCTYPE(B_CHECKPOINTER, "checkpointer", CheckpointerMain, true)
40+
PG_PROCTYPE(B_DEAD_END_BACKEND, "dead-end client backend", BackendMain, true)
41+
PG_PROCTYPE(B_INVALID, "unrecognized", NULL, false)
42+
PG_PROCTYPE(B_IO_WORKER, "io worker", IoWorkerMain, true)
43+
PG_PROCTYPE(B_LOGGER, "syslogger", SysLoggerMain, false)
44+
PG_PROCTYPE(B_SLOTSYNC_WORKER, "slotsync worker", ReplSlotSyncWorkerMain, true)
45+
PG_PROCTYPE(B_STANDALONE_BACKEND, "standalone backend", NULL, false)
46+
PG_PROCTYPE(B_STARTUP, "startup", StartupProcessMain, true)
47+
PG_PROCTYPE(B_WAL_RECEIVER, "walreceiver", WalReceiverMain, true)
48+
PG_PROCTYPE(B_WAL_SENDER, "walsender", NULL, true)
49+
PG_PROCTYPE(B_WAL_SUMMARIZER, "walsummarizer", WalSummarizerMain, true)
50+
PG_PROCTYPE(B_WAL_WRITER, "walwriter", WalWriterMain, true)

0 commit comments

Comments
 (0)