Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q9xqX-0001Ev-AO for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jun 2023 01:01:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q9xqT-0007SN-Nc for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jun 2023 01:01:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q9xqS-0007S3-Rf for pgsql-bugs@lists.postgresql.org; Fri, 16 Jun 2023 01:01:45 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q9xqP-002fOx-OD for pgsql-bugs@lists.postgresql.org; Fri, 16 Jun 2023 01:01:44 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 140FC5C010D; Thu, 15 Jun 2023 21:01:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 15 Jun 2023 21:01:40 -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:sender :subject:subject:to:to; s=fm2; t=1686877300; x=1686963700; bh=gw VWzYBwIRQacUPEwTHkEgp+mI3ryCV5cjUWj5nEbCc=; b=nXaexEsG6o/hdFkwGA Hv2EFkrLSBDdG9eiZAh+beckWqh6wfOpN1ssLg0HGVp5uKtUNWspjn+FcEPgKw95 IYsSywdDy2oHpd98PuRkxyAE4Z7Bjne90w5O7r1iS8gDo4rvdnRxUY5k82YWc8Wj fhNkWCS8sJBsQCloCTIYY0moFQur50H2fu2S5b6Fzst43YseR4Wyo7hUxOhrSSX2 3B8zS2tddD47j6TQyeWc8+khVyTuOVFjAj5nwcVEwTcut8IziYcHcmHnSni+fRES 4pKAR3psxU9BVjgSmeOalu5G24T4AtuTePowyzSlEce76i2R2Y17TDcX1juLYpN8 YHJw== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1686877300; x=1686963700; bh=gwVWzYBwIRQac UPEwTHkEgp+mI3ryCV5cjUWj5nEbCc=; b=To6z84lUIcD/EOWrSUun4jirYAv6R U82TYSce94IneN7I84kKpIFBBSOdlWfq9D+W9LhQTr8JyngLps3FIrwSaeexmCP5 XR/0kqQH/bTIXpgC1NkfBYDXWdfgK5NVf2shEgf84O8pgNA5t4uwg3oOIufhZLyK 2RPz+APTG5V49R/G2jS+n7SNtXA423nN3KBVG9Ij++XzTulDc4RENIQ7esXDK76i TIDyjIoCuW76fqvwLVUT4fn6nso/5ca4Rj3/0HOkqf5UMwnlbZPpf/T+NEkr5Pcc 5/1zhw9O9F8EP0uhbrg/ELPEiUpiLKKchTFViyuKJgApwlcCbi8dUXw3A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvfedggedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Jun 2023 21:01:37 -0400 (EDT) Date: Fri, 16 Jun 2023 10:01:33 +0900 From: Michael Paquier To: Andres Freund Cc: will@extrahop.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17973: Reinit of pgstats entry for dropped DB can break autovacuum daemon Message-ID: References: <17973-bca1f7d5c14f601e@postgresql.org> <20230614213724.gweo666oxqrugm44@awork3.anarazel.de> <20230614215744.ddeuii7jcojbp3yv@awork3.anarazel.de> <20230614223012.cfyzxyfnt3ggqkt4@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6qU/fYYiy7OeI3nj" Content-Disposition: inline In-Reply-To: <20230614223012.cfyzxyfnt3ggqkt4@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6qU/fYYiy7OeI3nj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 14, 2023 at 03:30:12PM -0700, Andres Freund wrote: > Attached is a rough prototype implementing this idea. Could you check if= that > fixes the issue? It requires a few manual steps, but I have been able to stuck the autovacuum launcher schedule. Nice investigation from the reporters. I may be missing something here, but finishing with an inconsistent database list (generated based on the pgstat database entries) in the autovacuum launcher is not something that can happen only because of a worker, right? A normal backend would call pgstat_update_dbstats() once it exists, re-creating a fresh entry with the dropped database OID. Is that right? + /* + * If we haven't connected to a database yet, don't attribute time to + * "shared state" (InvalidOid is used to track stats for shared relatio= ns + * etc). + */ + if (!OidIsValid(MyDatabaseId)) + return; Hmm. pgstat_report_stat() is called by standby_redo() for a XLOG_RUNNING_XACTS record so this would prevent the startup process =66rom doing any stats updates for the shared db state, no? Looking at the most recent things in this area, like bc49d93 or ac23b71, I don't immediately see why your new ordering suggestion would not be OK with MyDatabaseId getting set before acquiring the shared lock of the database, so as the stat entries don't get messed up. The result feels cleaner in the initialization sequence, additionally. So, nice. -- Michael --6qU/fYYiy7OeI3nj Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmSLtG0ACgkQnvQgOdby QH0LHRAAgnRqWGtRJCI3rm0ewS/tNVc7y0Q63hvEh7v+zJ6WrgjQQI5rjOhIKTIC 7xa4nTw/3cAL80iu5MrCViU6Ymitv/gtMnKqK7zST37x1QflGXaAW3TLE5uWiF2X V4+oTrm4nKNNFahSY3+qAhcIMfNvHQrSC55hSak/bD7om+oQj8v0maRkXuo2IDc8 F2XDQ2w3AMe4KZb8pJgqgHjUL8NacL8sop079fY8Hk0yuURe+4TF612CZu0KMr0E 24KWWSJu44GbAsHU13XAeqmySFZ9v6p5FuRN3RzKHP9Q/R6cYczOjGTRPRsyvBfg 2AiUz9e7Md+Yh0KkxNmBMd6D58utoNza3gniK2Rb2R8r5Wi7AdsfH5uXMqEYmA4G Ya0MzIjsKiX6/KPoLieItyo1sGX+jYvs6MJX59HiVY/Tzqie/FZZKfmQHy2hHLhX 5/2GpYcv6f2s7Yzp/7VkX7EmlPFo+mNydLwfkN/YiO7v5/U9MJW2od+Mwt/f90G4 eJOeMIaXohA9EsvqUFAKl8xlCVIXmAthnOj4yYF/v1Dm9vaXN2XYtvCrlvObZneP 1XevafZtIIE4J4Pvi5neyb1sA3B/AJIIt19w/+rkjx+kYMvluGYtBLlQ/P0v/TBp 4OeneFCwcqa/rzHEzbzF56P9OZYT4r3RYOM7BqLhUOwyhtOoWTk= =l4X3 -----END PGP SIGNATURE----- --6qU/fYYiy7OeI3nj--