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 1w0jRk-002A5o-0X for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 17:03: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 1w0jRi-00Fxb7-1w for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 17:03:39 +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 1w0jRi-00Fxaz-12 for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 17:03:38 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0jRg-00000002KRH-1Naw for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 17:03:38 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b943b75dc42so199268066b.3 for ; Thu, 12 Mar 2026 10:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773335015; cv=none; d=google.com; s=arc-20240605; b=DiyjUd0cLr2GfPrCzRX2PXF84ojoRKzhs3p/eSXSIgRNCwfsc8IEcoaFOF4ti8PD24 eg/kb7LOlEQvrTRNmuDlYaMLup4hoAhWa1pTFwbylT8/LrzObFQKk9f2dGB0phQEjdtV e5lMj4rVU9jAZd6wWemPYhvE4uL3/P1OR+W9IqxQDQbEsyfAE4VCRD1idkuKswbnYWid EQZMGQzKZUasxqB6gQ4GwrCEYCyuc+pm08SE/zmyXu1kr/REaWVgMqh5nkOs2/DW7j2G n3jP0WQTQ69ZSOfg5PsRo1z/yFFMOmnqQBLXZubff1+ieE4OmNOi2N+U0QIznZ+oBO17 rGbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=PYRpmDTeq/nOjQHqYYjQiTC5rrqcpDvNq7FbRQdrVoA=; fh=PqaSQVsDJACCL8FivO2TT2SDDCrZ4D9FkUje1OPJ9o8=; b=KFFOXp90PW8DAY+5lygrBP6J207aJjxd1S29tmsx4oo6IuCUIRDv0Zs7IxaKzPXjSP Q+ZSh1TdnSXSPie2fn6pDWXmlwlxmKKwPnHF2dOjJZlmfOPpaABSeVGdwp5pXYi0n1eb MTnn7DulVbSS+srbr+r8vQOaDtYMAspMWdiUj5YqtTbDTZoCNV6v/dfgsYJ4xG1m02gq TXOwloakiZitZ6YffeJePhoy4pOCWsh6ISxFSjmV9wFYL4s2KN+IVggqCePxfywqA/LS lKXE6oZj7zdTN9wXAgEbI4jCn4GHph3gzrT2ptcQzZ+nM0y985mLi4o/1poaXLhzERyU nyRg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773335015; x=1773939815; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PYRpmDTeq/nOjQHqYYjQiTC5rrqcpDvNq7FbRQdrVoA=; b=LnkvfEgibFBrI+lHyTiapp83khyBe04KqfMGCA29fTG+qInu5aA/of2rBKNhAy1W67 FDKqtj5VdBKrzIJXxGPDOL77XzJOhlMw+NvHOmCC29SOy/KQiJX6bkK122ydK4GOHkHz UxDVc7IKyLwPWpMJ7OoZzt9oCkn8UwgghGNuIsyYfUG4cQHOJte58xEfZVxTZDOjQMXI LsKbf+CevUigpIb/4rQLYUPQ8CXspBEYGOjpfnshDoSVvVuPVRls2R+zz+60q1Af0LKr Za1kLUfkctDcOM7LlF/mIWbl7EaH1NQssMqc6415Ra6PvZCIEMsVG+pAXpgbUjNB+D+X J09g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773335015; x=1773939815; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=PYRpmDTeq/nOjQHqYYjQiTC5rrqcpDvNq7FbRQdrVoA=; b=DmkY2yWZddRtjj7w+IvWiI2Z10eKhjpKflebpRXzqdR7t+jX3i/MiGV2VU0gWA5W7H u8yXQXG24Dnb4YRvslaeyPuLxjQZgh69tt3JcxC1qnfOrlmv+0fNOg72TVtaR2ZB1Ng7 gLqQgQ6XOw1ZaQb9D2BdTCo97teXP5DT9T5js7X/M6oKGT7HmzJGeO5a1dJer5gDYJ5C McykjauUm+jIcF/DEXCr3RK9nGVhtQGp+ZGFelHGcgpSdHDxYHEfCOWjJx837528oZRd /Cey1XymtkcHxjKWC+pdJZl+cDPYghGhqGgBIPcKXhQivprmA3Nj0wZQmkwr9XZgZXgT YdNg== X-Forwarded-Encrypted: i=1; AJvYcCUaYmH4Zxx1mV2Qn5zTB7IS+ai6sKi6OkPpjKzE8IKBtB7OrVEd1YNTpwivqmoll3gx3kbNNTyMnJXprHIc@postgresql.org X-Gm-Message-State: AOJu0YzVm+B3n/kL/mx8v5Mdf9Bpz7zJySSQj2pJ9EMSjkMs858ghItj Z4wsilF10TZGHT+y16W0nFiy/KdF3ZYXKZuEC9T2A36ym1D+tSMuZP++WOApGoaJC5GLWWTbkl6 UzF8Oumcqv3xAuex4oCRcCS92YfdzhnM= X-Gm-Gg: ATEYQzyqcCnq6oc6I9jSaxN/ELvHtA1Mv0i6NwFsMmwWRaJG9ruu12ixAYJmEk923dg fmzbK1xWwuecAdV892Wms27Ed9qBTWk7m9uBY4b4z1mN+FDsElc53n88Kh0hatU2zzG7zyYK0Ns +ghmicwp/sAAnZzNC6cjoca2StS7qVNNpvRlRsmDvEFYiI2FAeOuvXE3Hs4WZVJV3Isq03lQhLu 1FHitZpTguQ0vgazWiRKvygDZ/dE6fEJYUnYAC1R9RTL4vaVvh+HGd3ue9u6+BmKi+emMfK6tqX E25zDaXurVqK4IGkg92XEOdrfm8x6yrEaI7oRvKMN4KTqoa8cw== X-Received: by 2002:a17:906:eb57:b0:b96:f488:1903 with SMTP id a640c23a62f3a-b9765348085mr6308966b.39.1773335014621; Thu, 12 Mar 2026 10:03:34 -0700 (PDT) MIME-Version: 1.0 References: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> In-Reply-To: <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> From: Robert Haas Date: Thu, 12 Mar 2026 13:03:21 -0400 X-Gm-Features: AaiRm50aJ7iu-YsTMd1TkivFj2mumKbkW_TPHx9hkdEts9fnbRUCJU36I0mWc5k Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Heikki Linnakangas Cc: Ashutosh Bapat , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Mar 6, 2026 at 9:13=E2=80=AFAM Heikki Linnakangas = wrote: > 1. _PG_init() gets called early at postmaster startup, if the library is > in shared_preload_libraries. If it's not in shared_preload_libraries, it > gets called whenever the module is loaded. > > 2. The library can install a shmem_request_hook, which gets called early > at postmaster startup, but after initializing the MaxBackends GUC. It > only gets called when the library is loaded via shared_preload_libraries. > > 3. The library can install a shmem_startup_hook. It gets called later at > postmaster startup, after the shared memory segment has been allocated. > In EXEC_BACKEND mode it also gets called at backend startup. It does not > get called if the library is not listed in shared_preload_libraries. > > None of these is quite the right moment to call the new > ShmemRegisterStruct() function. _PG_init() is too early if the extension > needs MaxBackends for sizing the shared memory area. shmem_request_hook > is otherwise good, but in EXEC_BACKEND mode, the ShmemRegisterStruct() > function needs to also be called backend startup and shmem_request_hook > is not called at backend startup. shmem_startup_hook() is too late. I believe that the design goal of 4f2400cb3f10aa79f99fba680c198237da28dd38 was to make it so that people who had working extensions already didn't need to change their code, but those for whom the restrictions of doing things in _PG_init were annoying would have a workable alternative. I think that's a pretty good goal, although I don't feel we absolutely have to stick to it. It could easily be worth breaking that if we get something cool out of it. But is there a reason we can't make it so that this new mechanism can be used either from _PG_init() or shmem_startup_hook()? (I assume there is or you likely would have done it already, but it's not clear to me what that reason is.) --=20 Robert Haas EDB: http://www.enterprisedb.com