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 1sMLOE-001ojN-Hv for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Jun 2024 05:40:19 +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 1sMLOC-0028rb-MM for pgsql-hackers@arkaria.postgresql.org; Wed, 26 Jun 2024 05:40:17 +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 1sMLOB-0028rT-5g for pgsql-hackers@lists.postgresql.org; Wed, 26 Jun 2024 05:40:16 +0000 Received: from fout3-smtp.messagingengine.com ([103.168.172.146]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMLO8-003Ajc-DS for pgsql-hackers@postgresql.org; Wed, 26 Jun 2024 05:40:14 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 0E6D713802BA; Wed, 26 Jun 2024 01:40:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 26 Jun 2024 01:40:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1719380411; x=1719466811; bh=k51zPHLq9N zhJsuhTTUMMDNwf9D71XB96EbVarMx5+s=; b=RVOiSKlz8BMBBvtpT99xUZdsQi r46OwCPufAQAEMtNGrcJdxbKbsEJXWzWa2FsUKdQFlAyhs8rjBDlkGi+jcjgboaz 1VhZ+MLRywq+DlKEVmYN5JNTMSVN0fxNqIlVcTlswesjcMNckBih76IAHroyZY4p fMkWqE0MGSXsGZ64jZ6OYiVUJ3JkoD01k/VE9N8rsfaFu3E+WtVZoRw8oyKerIK4 myYGW/xa/k9lxLbpyCFfrN2HRYPYe0XUFnH23DXwl9idSKoYIuWSvgBtiLZgav87 nNp0nAOpXjNRYorURDfPF4durnSJDNS5xhJeEF5BZPXsRP4CzIGxbMGDElrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719380411; x=1719466811; bh=k51zPHLq9NzhJsuhTTUMMDNwf9D7 1XB96EbVarMx5+s=; b=mpKGwcFmwqy+mAWGHUuSoXeeT8E3BsyFUmCbiDDZnB67 tgy1SKNPbGxnTYpcESZcIy8vKoGjMMJbgX/uwhXj2FWYGmozOTlKmt4r+alQSoXC +skkG+6LucQbSp9m9CHZZIdIdwAZqygE7pXZbwiG1OOqnrImo77Qbbh3tDUrryXO KHen1r9mfGvZiPRSoiix+sGtLCywBhLgKyUsCDxXA44z8YWgYM108NHx1YCaFbXd stg7P/otAnBTvmbvdTMg6Z5Laz6zsYy2z2E81sBoOByJ6cyrOSYA0H9WN7yR/GHi QcVXPRnpLwEIXBw1r9jeV3jYRHwiU9GpBjILSHJoew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddugdeljecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeg geffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 26 Jun 2024 01:40:08 -0400 (EDT) Date: Wed, 26 Jun 2024 14:39:57 +0900 From: Michael Paquier To: Anthonin Bonnefoy Cc: PostgreSQL Hackers Subject: Re: Fix possible overflow of pg_stat DSA's refcnt Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ClmJxpeNE9RCu9j0" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ClmJxpeNE9RCu9j0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 25, 2024 at 05:01:55PM +0200, Anthonin Bonnefoy wrote: > During backend initialisation, pgStat DSA is attached using > dsa_attach_in_place with a NULL segment. The NULL segment means that > there's no callback to release the DSA when the process exits. > pgstat_detach_shmem only calls dsa_detach which, as mentioned in the > function's comment, doesn't include releasing and doesn't decrement the > reference count of pgStat DSA. >=20 > Thus, every time a backend is created, pgStat DSA's refcnt is incremented > but never decremented when the backend shutdown. It will eventually > overflow and reach 0, triggering the "could not attach to dynamic shared > area" error on all newly created backends. When this state is reached, the > only way to recover is to restart the db to reset the counter. Very good catch! It looks like you have seen that in the field, then. Sad face. > This patch fixes this issue by releasing pgStat DSA with > dsa_release_in_place during pgStat shutdown to correctly decrement the > refcnt. Sounds logic to me to do that in the pgstat shutdown callback, ordered with the dsa_detach calls in a single location rather than registering a different callback to do the same job. Will fix and backpatch, thanks for the report! -- Michael --ClmJxpeNE9RCu9j0 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmZ7qa0ACgkQnvQgOdby QH1d2w//QYD54tCYTXmOlT9oMG0IFPd0A+YNvhuX8qsW2oEtQicphBCv8djV/xta eWn4hVtMAtZJ7ZFWBCdHqBoV9whYmGsS5SuLXhWdqlTHWch9P8X+spR8WUGWuHT1 EFW3VdOf2py5S5fvFdv7lNh+ByieFfLQgOgmDfeqDsXHS1AyOlSEbXwHrSFvSNKx dq+zjRj1B01gaM2QFtPCHug4jV4jP5rCch6hx1RLaRdqtsU4jq8nzdJsGJo7x3Ic IDpDqJz6koD40DKCAd5ynwNGn3C/Z0H1EeA1zMfuM/c0OmR+MPxRLi4+XubR5vCf IVUOEDxCoy3+g+PIvK4X3vK6jqmhhtha0lwOv/RIRxO2Z12NODqFFtfc9bXght7g lm1PnISvEeXFn3OCAiFA7EVzYPpXwFJyoencAOewVlU0D6A9M2TSb4OBdgmuXiG9 bdkaxtvJEFy8gmS4IwEn1XkBlLPDBlGlbDixA+XoeQq8hD1cGxUM2xF6a5gkthT0 7g4E1gW1R0+rHtfV4R+wzqmd8g8Oxy3jaNY1GlQnpNKKjjsk91PpkIe16rCF0KSb lpllcwDRzNpERfwN9EhDAF7Kv7cRM7og1rL+FdE570WyV2RwWj0WDKxUfvVGA/bH CKA69pQPXxHfCEGeBpn1wjqSUc8ulMpKMfCIVjONj15Nx13J7Sg= =oxao -----END PGP SIGNATURE----- --ClmJxpeNE9RCu9j0--