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 1w2wb5-000kfC-2w for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2026 19:30:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2wb4-00DrLu-2N for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Mar 2026 19:30:26 +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.96) (envelope-from ) id 1w2wb4-00DrLl-15 for pgsql-hackers@lists.postgresql.org; Wed, 18 Mar 2026 19:30:26 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w2wb1-00000000PoV-0EG9 for pgsql-hackers@postgresql.org; Wed, 18 Mar 2026 19:30:25 +0000 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b97c44417ffso18449266b.2 for ; Wed, 18 Mar 2026 12:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773862223; cv=none; d=google.com; s=arc-20240605; b=Au1yXFcwLjhD/63qc7CFAzDuwl5VOyPaLzvlHDhMeQVHVDk7xBQbG7wmhMbWYxKOfR dxDjLuLixrDrnC8MqxCFFVLAnK8d7ueSeYdiaH9KplpTQe947VuBRlg1JzeCbQBEGsLn 8IF0HBKZgjWZEH+Nc81WsisGmLbrtZ+NB82mfvFjPNU+2Pt+iJ7Z1WwwQ1ZAeGp7hZAG 82K1ZGtk5+MAzU2MqKCTFS8Etkip0brQJF2ugUYuWnvBXCvdPNcdBNa+Yw2nLxTU5ozg aAGBUq95w/ugLEVbsH34Ambr+WQv9o2+HVHNP1BE0KREZIKqCnWT4YORUnf4jgQ0eAeY C35A== 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=CplU+NuZN1623KBPzms7J+luJT/RHnZYdf1FmJRU418=; fh=/D9mj/rYPYJNkIHDZopzp6S0+EoE5mx2yf8zsbDPUIY=; b=Rr8YHeb0Pqm9cmocfwX9VCjKhjk/QNkgKy/FS5SMUnLz/ugYQ2Ph31f809ftEFx/oI Y74dTGxPuE4yWC40lS0S9/mrWhypX/gW4BupR7yIOoaE0oodX2tOYCdDmQbLuw5Qs9Yq hK07uWrjiWvEs0zrXjWEro/78902AsvTnsXvapnI7W9spzSJgBq6kAsMSfoWK07oPttv VFkN1wt9IX6539dG+3hr81Mg6xZ1okVc3Rvzmbuq51NohqDo+4S2du6c6BRqPZzDgZFr otZ5Z29MwPFGlzRetiEWWHlQ4/AAKvZRTnGkZM0KrPFSyaNGMww1uxdRCy1OYclKzrlI OBmw==; 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=1773862223; x=1774467023; 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=CplU+NuZN1623KBPzms7J+luJT/RHnZYdf1FmJRU418=; b=giza31+ucI2W8R/jbImWzxgdR64HuMd6NTD7TXc/LvbDauaLBfG3Wpc5fzrpfAuo4m FFobQjBPnIDl3PMc3WCEH/sWhMUEo9R7p+rQ4TJN0LrY/KdJc7aUyaFsZGMI7PCs4lII D1zwluqqMDcYVhy9sbm5jwaOLGYtC9R0StI6oMyJJhARt2Iyoj2Pbka7nnhPNIUUnuNI oJCdOI5q3MI3tvfssANEdi5gTd0320YPpnjUX1CILxoitC1Nqp45PBT/+EvbNDw7qgvK sx2+ZnrFHRz+3s9LXa7OTjJaqBQVz3zKtRT4q/b+LdUR5RBdl70hwMWSW7REgQGt+Y6X oxmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862223; x=1774467023; 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=CplU+NuZN1623KBPzms7J+luJT/RHnZYdf1FmJRU418=; b=mknsSINCHr2rE6oWi6FSkoyyA/XH/mhv4kFSHF895kEnc6FNs50JRKKrViWQ95LaIP L/LvmYrfIUC1+V+F4KFpBATPoD2PqQRUesW/BXzwn0iRkDl6jBZGs1WE4yV6g4Bjnu1l 94v2wmnT+SgVKZLahtlkZaorDohWTUDCiUbt4P4sJu4WCayiDFYVuedfpQqOzBB79wA2 RcXXAb4VYrrGT11NJq1CbxKl3gxxn0w91NbKK2aLcvijbO26gKcaAARAdlF3AL2eBfy/ SO617Xb+Ts27VzXhnYGZ2E10aRuLlEhFkXezo2igTP2dWI/vS6APDkDpf61cB+2n9ehk YLLA== X-Forwarded-Encrypted: i=1; AJvYcCWiQf+9qMzDC584M165KF+VajL+99sC7gPX/vdTz5hCq81mP1y4zUQy3GG22eXBxKKC33fCJfHg700HC829@postgresql.org X-Gm-Message-State: AOJu0YxWLHnPtLAiDaPlSgMX0KyJGPHtEcLG1LtI/OXpyT5AhzFbJOpI c8FC4G5olCRfItYZe199wY8qZ5KCboeMnPCNFpx5iVBwMny+EVPWfzjv/cUiheI3ErM7pB0zLY1 nGJA+LQznpcm7Zh7cuZQ5Z6+lwvxsCZI= X-Gm-Gg: ATEYQzzITyZKIxv46acAZS6eMZPIJg90maV9ibCStpkyL68dSBtRPPVMDtsCGRlrJn4 aA9T80P5qut+QwL9nCnb2OncWcri32vDRAmKyDSjwr862NWdLZahaBbxB4e/W/2mlNee9+kXT1y LF3Gpww14S8XJmMy9kKC0CNDWRkl4C/fAqeG4rOVhbrad3aqm7jZlQQz3UgZVewCchlfM2DCGia EddaoeoUzP2lsGK+nxCfm0w99/jshLzkQEpeK9M5GR2xFVoV/Woxx8d2x1JqMpXODlVOLuoPDV2 2VjFFIMQkKIK8BRn/ero7OUX4ZeAgnB1SJGxL8mwlrrhV2Se/Q== X-Received: by 2002:a17:907:bd0:b0:b97:61e2:95ea with SMTP id a640c23a62f3a-b97f49055aamr199877466b.20.1773862222907; Wed, 18 Mar 2026 12:30:22 -0700 (PDT) MIME-Version: 1.0 References: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> <26c766d6-db0f-43d3-a618-44f8d40a3121@iki.fi> <62b8dc23-8f6a-4cac-91ff-f74bb5bc159a@iki.fi> In-Reply-To: From: Robert Haas Date: Wed, 18 Mar 2026 15:30:10 -0400 X-Gm-Features: AaiRm53YN4-EF5cerAV1ZmsX8Kl5lGWYX_3CVAPdWKGLUEUSkrbxHphKmTXtFb8 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 13, 2026 at 7:41=E2=80=AFAM Heikki Linnakangas wrote: > Yeah. IMHO the existing shmem_request/startup_hook mechanism is pretty > awkward too, and in most cases, the new mechanism is more convenient. It > might be slightly less convenient for some things, but mostly it's > better. Would you agree with that, or do you actually like the old hooks > and ShmemInitStruct() better? I'd say it's not massively different one way or the other. Looking at the pg_stat_statements changes in particular, I feel like in v2, it was actually worse, because you didn't get manage to get rid of pgss_shmem_request(), but it was no longer the thing requesting shmem. v3 is better in that regard: you get rid of some complexity in exchange for what you add. It's not amazing, though: pgss_shmem_startup() now has nothing to do with the name of the hook, which is not this patch's fault but also isn't solved by it. I wonder why in the world somebody decided to jam all of this non-shmem-related logic into this function, and why they didn't add a comment explaining why it was here and not someplace else. One of the worst things about this area is that I often end up having to trace through a bunch of postmaster startup logic to figure out whether any given bit of code is actually in the right place, and that makes me feel like the hooks are badly designed. pgss_shmem_startup() is a good example of that, and the fact that it needs an IsUnderPostmaster check is another. We should somehow try to make it clear what happens with this new mechanism if a module is loaded via shared_preload_libraries vs. if it's loaded via LOAD or session_preload_libraries or whatever. Writing modules that don't require shared_preload_libraries is a boon to users, because they can be added to a production system without a server restart. I wonder whether this new facility handles that case better, worse, or the same as existing facilities. > One such wrinkle with ShmemRegisterStruct() in the patch now is that > it's harder to do initialization that touches multiple structs or hash > tables. Currently the callbacks are called in the same order that the > structs are registered, so you can do all the initialization in the last > struct's callback. The single pair of shmem_request/startup_hooks per > module was more clear in that aspect. Fortunately, that kind of > cross-struct dependencies are pretty rare. So I think it's fine. (The > order that the callbacks are called needs be documented explicitly though= ). > > If we want to improve on that, one idea would be to introduce a > ShmemRegisterCallbacks() function to register callbacks that are not > tied to any particular struct and are called after all the per-struct > callbacks. I think the whole idea of ShmemInitHash() and ShmemInitStruct() is relatively poorly designed in this regard. Ideally, I want to initialize all the shared memory that belongs to me, and that might include arbitrary data structures, but the current design kind of thinks that I want one struct or one hash table and nothing else. If we're redesigning this mechanism, it would sure be nice to improve on that. Looking just at the pg_stat_statements changes, I think my overall view on this right now is that it's not terrible, but I'm also not that happy about introducing yet another way to do it for this amount of gain. To me, it doesn't yet rise to the level of a clear win. --=20 Robert Haas EDB: http://www.enterprisedb.com