Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vT0bo-00BFtm-1D for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 16:30:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vT0bm-005Y0Q-0d for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 16:30:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vT0bl-005Y0I-2b for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 16:30:38 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vT0bj-0044cg-18 for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 16:30:37 +0000 Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 74F481400180; Tue, 9 Dec 2025 11:30:33 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Tue, 09 Dec 2025 11:30:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1765297833; x=1765384233; bh=Z NYmuXshbGL0I7Gf0tD0VtQzwtu4c65U/Ulkr01q3Jw=; b=Y9ZaXTznr01rXJZfQ SyGYiaEikFhHSC98nLv8GVZ9+zw5xMUQ9UE9vu7cXI7rhcbL603jQ3jat6Yx8uys 2cfhf89HP4qpUTI6LkrCYVpkpCSLlEbwVzghA1U2Q/XDCXRUiJ0udAIaqdvU1In2 6HYPNWjzuX19tpEUfdB2cnE4FciNXgJaQ0S7MVkutUUDGsKNwAx83ua/MM7QJJZa oID0zdQJGHTF+hfgkib5be45Ct+ibSSMHrn6orXZ0NCMqeH9hZKGmFW928aOfV80 IXK2ax64G+23cCgkG3HRXKYja4iQTdmJZuPLybgsVzs+6mygHZTUt0rMKvAozBQE K19ZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvtddtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfggtggugfgjsehmkeerredttdejnecuhfhrohhmpeetlhhvrghrohcu jfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqeenuc ggtffrrghtthgvrhhnpeduleekkefgtddttedtkefguddvieffleetgeejiefhteehkeev feettdduvdfhueenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghr rhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtghpthhtohephedpmhhouggvpe hsmhhtphhouhhtpdhrtghpthhtoheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhr tghpthhtohepvghulhgvrhesvghulhgvrhhtohdrtghomhdprhgtphhtthhopehlihdrvg hvrghnrdgthhgrohesghhmrghilhdrtghomhdprhgtphhtthhopehjrghpihhnlhhisehh ohhtmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhish htshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 9 Dec 2025 11:30:32 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1765297829; bh=QA2xaP716k5KW72P0+ht9m5rCpDP7tzXTEH/mD4ecBE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Kwu2wpiOka5052h5rule0yKUgWS18quYISpnPnOl37diugGwc6pAICqYjc/SoG/2P kkvxEXZb4CaAIIX8MWm1Ln0+JCPOX824XNADaw5Y5WnOXk0Y6xu9NWlc6pER0Qpzll /wbrRFPI62xd+xMXGoqMPq0KYbHILV7hlGrsD2fHbLtSBmphz4qTXmQazcbGQasSxN p7EnzjeAvWkkiMIaQqUW1O3aFJGTh0phArZO8mW/TitW2NJc2wg1oSzkqcbifjZQnK PPEBmwZfa6ZuAFRUl2DMR9o+5ycmpXKjc2yrRjn0Bgoxau86cYti9InJrGKBV4EjZ0 DAFeJvuYXpb5w== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 8FC417B; Tue, 09 Dec 2025 17:30:29 +0100 (CET) Date: Tue, 9 Dec 2025 17:30:29 +0100 From: Alvaro Herrera To: Euler Taveira Cc: japin , Andres Freund , pgsql-hackers@lists.postgresql.org, Chao Li Subject: Re: log_min_messages per backend type Message-ID: <202512090935.k3xrtr44hxkn@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ogkssrz7kzkktwbw" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202512090853.hk6e6t56bq5z@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ogkssrz7kzkktwbw Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit BTW another thing I realized while looking this over, is that we quite uselessly transform the integer backend type to a string, pass it as a string using the --forkchild= argument to the child process, then parse the string back to an int to use as an array index. It would be much easier to just use the integer value everywhere, as the attached shows. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "I love the Postgres community. It's all about doing things _properly_. :-)" (David Garamond) --ogkssrz7kzkktwbw Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename*0="0001-Use-integers-not-strings-to-identify-backend-type.patch."; filename*1=nocfbot From 4c2e63bc3c78b567e83a4d6d0df60ddeb0f51a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Herrera?= Date: Tue, 9 Dec 2025 15:29:43 +0100 Subject: [PATCH] Use integers not strings to identify backend type --- src/backend/postmaster/launch_backend.c | 32 +++++++++---------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index 976638a58ac..3606a569758 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -162,7 +162,7 @@ static bool save_backend_variables(BackendParameters *param, int child_slot, #endif const void *startup_data, size_t startup_data_len); -static pid_t internal_forkexec(const char *child_kind, int child_slot, +static pid_t internal_forkexec(int child_kind, int child_slot, const void *startup_data, size_t startup_data_len, ClientSocket *client_sock); @@ -217,7 +217,7 @@ postmaster_child_launch(BackendType child_type, int child_slot, ((BackendStartupData *) startup_data)->fork_started = GetCurrentTimestamp(); #ifdef EXEC_BACKEND - pid = internal_forkexec(child_process_kinds[child_type].name, child_slot, + pid = internal_forkexec(child_type, child_slot, startup_data, startup_data_len, client_sock); /* the child process will arrive in SubPostmasterMain */ #else /* !EXEC_BACKEND */ @@ -282,7 +282,7 @@ postmaster_child_launch(BackendType child_type, int child_slot, * - fork():s, and then exec():s the child process */ static pid_t -internal_forkexec(const char *child_kind, int child_slot, +internal_forkexec(int child_kind, int child_slot, const void *startup_data, size_t startup_data_len, ClientSocket *client_sock) { static unsigned long tmpBackendFileNum = 0; @@ -358,7 +358,7 @@ internal_forkexec(const char *child_kind, int child_slot, /* set up argv properly */ argv[0] = "postgres"; - snprintf(forkav, MAXPGPATH, "--forkchild=%s", child_kind); + snprintf(forkav, MAXPGPATH, "--forkchild=%d", child_kind); argv[1] = forkav; /* Insert temp file name after --forkchild argument */ argv[2] = tmpfilename; @@ -392,7 +392,7 @@ internal_forkexec(const char *child_kind, int child_slot, * file is complete. */ static pid_t -internal_forkexec(const char *child_kind, int child_slot, +internal_forkexec(int child_kind, int child_slot, const void *startup_data, size_t startup_data_len, ClientSocket *client_sock) { int retry_count = 0; @@ -444,7 +444,7 @@ retry: #else sprintf(paramHandleStr, "%lu", (DWORD) paramHandle); #endif - l = snprintf(cmdLine, sizeof(cmdLine) - 1, "\"%s\" --forkchild=\"%s\" %s", + l = snprintf(cmdLine, sizeof(cmdLine) - 1, "\"%s\" --forkchild=%d %s", postgres_exec_path, child_kind, paramHandleStr); if (l >= sizeof(cmdLine)) { @@ -567,8 +567,8 @@ retry: * to what it would be if we'd simply forked on Unix, and then * dispatch to the appropriate place. * - * The first two command line arguments are expected to be "--forkchild=", - * where indicates which postmaster child we are to become, and + * The first two command line arguments are expected to be "--forkchild=", + * where indicates which process type we are to become, and * the name of a variables file that we can read to load data that would * have been inherited by fork() on Unix. */ @@ -579,7 +579,6 @@ SubPostmasterMain(int argc, char *argv[]) size_t startup_data_len; char *child_kind; BackendType child_type; - bool found = false; TimestampTz fork_end; /* In EXEC_BACKEND case we will not have inherited these settings */ @@ -599,21 +598,12 @@ SubPostmasterMain(int argc, char *argv[]) if (argc != 3) elog(FATAL, "invalid subpostmaster invocation"); - /* Find the entry in child_process_kinds */ + /* Parse the --forkchild argument to find our process type */ if (strncmp(argv[1], "--forkchild=", 12) != 0) elog(FATAL, "invalid subpostmaster invocation (--forkchild argument missing)"); child_kind = argv[1] + 12; - found = false; - for (int idx = 0; idx < lengthof(child_process_kinds); idx++) - { - if (strcmp(child_process_kinds[idx].name, child_kind) == 0) - { - child_type = (BackendType) idx; - found = true; - break; - } - } - if (!found) + child_type = (BackendType) atoi(child_kind); + if (child_type <= B_INVALID || child_type > BACKEND_NUM_TYPES) elog(ERROR, "unknown child kind %s", child_kind); /* Read in the variables file */ -- 2.47.3 --ogkssrz7kzkktwbw--