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.94.2) (envelope-from ) id 1rSM7G-00DEpH-Im for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 19:07:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rSM7F-00FQhC-GZ for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 19:07:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSM7F-00FQh3-6w for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 19:07:21 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSM77-0030Us-Cf for pgsql-hackers@postgresql.org; Tue, 23 Jan 2024 19:07:19 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 4TKGmX72cYzyRB; Tue, 23 Jan 2024 21:07:08 +0200 (EET) Message-ID: <8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi> Date: Tue, 23 Jan 2024 21:07:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Refactoring backend fork+exec code Content-Language: en-US To: Andres Freund Cc: Tristan Partin , pgsql-hackers , Thomas Munro References: <7a59b073-5b5b-151e-7ed3-8b01ff7ce9ef@iki.fi> <20230710225043.svl7fqxecwshwc7a@awork3.anarazel.de> <119551e6-60f6-49b2-ae04-a382a89f900c@iki.fi> <20231130202648.7k6agmuizdilufnv@awork3.anarazel.de> <59527c9b-c3f7-4d0c-a3f1-00d0ed5cc186@iki.fi> <20240122210740.7vq5fd4woixpwx3f@awork3.anarazel.de> From: Heikki Linnakangas In-Reply-To: <20240122210740.7vq5fd4woixpwx3f@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 22/01/2024 23:07, Andres Freund wrote: > On 2024-01-10 14:35:52 +0200, Heikki Linnakangas wrote: >> @@ -5344,31 +5344,31 @@ StartChildProcess(AuxProcType type) >> errno = save_errno; >> switch (type) >> { >> - case StartupProcess: >> + case B_STARTUP: >> ereport(LOG, >> (errmsg("could not fork startup process: %m"))); >> break; >> - case ArchiverProcess: >> + case B_ARCHIVER: >> ereport(LOG, >> (errmsg("could not fork archiver process: %m"))); >> break; >> - case BgWriterProcess: >> + case B_BG_WRITER: >> ereport(LOG, >> (errmsg("could not fork background writer process: %m"))); >> break; >> - case CheckpointerProcess: >> + case B_CHECKPOINTER: >> ereport(LOG, >> (errmsg("could not fork checkpointer process: %m"))); >> break; >> - case WalWriterProcess: >> + case B_WAL_WRITER: >> ereport(LOG, >> (errmsg("could not fork WAL writer process: %m"))); >> break; >> - case WalReceiverProcess: >> + case B_WAL_RECEIVER: >> ereport(LOG, >> (errmsg("could not fork WAL receiver process: %m"))); >> break; >> - case WalSummarizerProcess: >> + case B_WAL_SUMMARIZER: >> ereport(LOG, >> (errmsg("could not fork WAL summarizer process: %m"))); >> break; > > Seems we should replace this with something slightly more generic one of these > days... The later patches in this thread will turn these into ereport(LOG, (errmsg("could not fork %s process: %m", PostmasterChildName(type)))); >> diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c >> index 1a1050c8da1..92f24db4e18 100644 >> --- a/src/backend/utils/activity/backend_status.c >> +++ b/src/backend/utils/activity/backend_status.c >> @@ -257,17 +257,16 @@ pgstat_beinit(void) >> else >> { >> /* Must be an auxiliary process */ >> - Assert(MyAuxProcType != NotAnAuxProcess); >> + Assert(IsAuxProcess(MyBackendType)); >> >> /* >> * Assign the MyBEEntry for an auxiliary process. Since it doesn't >> * have a BackendId, the slot is statically allocated based on the >> - * auxiliary process type (MyAuxProcType). Backends use slots indexed >> - * in the range from 0 to MaxBackends (exclusive), so we use >> - * MaxBackends + AuxProcType as the index of the slot for an auxiliary >> - * process. >> + * auxiliary process type. Backends use slots indexed in the range >> + * from 0 to MaxBackends (exclusive), and aux processes use the slots >> + * after that. >> */ >> - MyBEEntry = &BackendStatusArray[MaxBackends + MyAuxProcType]; >> + MyBEEntry = &BackendStatusArray[MaxBackends + MyBackendType - FIRST_AUX_PROC]; >> } > > Hm, this seems less than pretty. It's probably ok for now, but it seems like a > better fix might be to just start assigning backend ids to aux procs or switch > to indexing by pgprocno? Using pgprocno is a good idea. Come to think of it, why do we even have a concept of backend ID that's separate from pgprocno? backend ID is used to index the ProcState array, but AFAICS we could use pgprocno as the index to that, too. -- Heikki Linnakangas Neon (https://neon.tech)