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 1q9yjn-0004I9-SQ for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jun 2023 01:58:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q9yjl-0006XX-Pl for pgsql-bugs@arkaria.postgresql.org; Fri, 16 Jun 2023 01:58:53 +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 1q9yjl-0006UW-FP for pgsql-bugs@lists.postgresql.org; Fri, 16 Jun 2023 01:58:53 +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 1q9yje-002fyd-AE for pgsql-bugs@lists.postgresql.org; Fri, 16 Jun 2023 01:58:52 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7CEAE5C011D; Thu, 15 Jun 2023 21:58:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 15 Jun 2023 21:58:45 -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=1686880725; x=1686967125; bh=YV Z7Eitck+WMbzQKf1GlQz5GhTmrtWvHpP04nfbtzIw=; b=uUEydpFPMHujUuU+gz D9cVjRAUGUoYiHJ80Z2x1Hx0EWpwehksP9Y86SdORmfSslgJ6JTjtaN3pP8Kv46V yOxBgOpXoQGxW7SBawUXIW/78h/C0NQIZDx0d8/33wskTLdOhiyHXXG1148kokZc jL7lXxUMipxW3aimiQ7Z2Ph+mwxBZu/PsEA9gjcOeJA3qZEJgXHE5pbj1q4ctsXf /8cvAvJ42qxhLN5YbNAG0CQCm5egjoqsd2ez3jdC67DNxXBSXQRsdXAn4y5YqiZS F8A1k7ShoAZyNdb/yx0dw4INbX5Lq6w+YWa0MRkW/paMvl464ltzRMldEmtf/9Q+ E5vQ== 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=1686880725; x=1686967125; bh=YVZ7Eitck+WMb zQKf1GlQz5GhTmrtWvHpP04nfbtzIw=; b=K3oTiDogkRNzkhlsPysqF0/UvqMHa hkC4RbJOKxoY0UCQ5ssTs2K8vupEJZp3o+GuR7UX1qOD+6Xyg3yJsi/9MVpJfTwW k4R9AK6NxmiNFcVuqksumCodSNK/iLbqe/EBFRZ+/YvKtGMXXdAp/t6gZUQ7lfPm jtaUXrMsxbPAiSr9cwKMJoeXtyQrN3Mw8aXJNdvYXSksG58ZUM4XKk9oj63ZK5J4 rEq5jLNKy9ytJRbd13UI/evpYhJLqB8BKwQEoWCkWATPVXL8ZPULoClrSRc6k5Wy WfL4S0P8m1LB2nSccNH2DxdAJGC4tghl6d5UV4U80XZWMVb05SuLH5m5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedvfedgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tdejnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeu ieeuieevueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 15 Jun 2023 21:58:42 -0400 (EDT) Date: Fri, 16 Jun 2023 10:58:38 +0900 From: Michael Paquier To: Will Mortensen Cc: Andres Freund , pgsql-bugs@lists.postgresql.org, Jacob Speidel 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="7q0qDqfH2O9te2Gs" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7q0qDqfH2O9te2Gs Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jun 15, 2023 at 06:36:41PM -0700, Will Mortensen wrote: > On Thu, Jun 15, 2023 at 6:01=E2=80=AFPM Michael Paquier wrote: >> 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? >=20 > Yes, sorry, Jacob was able to repro with a normal backend just now. We > probably should have tried that earlier. :-) Okay, thanks for confirming. Yes, I was able to stuck the scheduler for both. FWIW, I have initially hardcoded a stop point with an on-disk file around InitPostgres() before we take the shared lock. But thinking harder, it is possible to be sneaky with the following steps to get these incorrect stat entries: 1) LOCK pg_database in a first session, on a database different than the one to drop. 2) Connect with a second session to the database to drop, stuck because of the previous LOCK when scanning pg_database to find the tuple OID, during connection startup, just before taking the shared lock. 3) Third session executing DROP DATABASE, with a session that connected before the pg_database lock. 4) Commit transaction of first session to release pg_database lock, the database is dropped and the second session fails to connect with the database renamed. > I'm also unsure if reiniting the pgstats entry (as opposed to creating > a new one) is actually necessary or just what we happened to observe. > We're definitely not very familiar with these internals. :-) The proposed patch does better than that, actually, and takes the approach of not touching the stats for the database dropped/renamed by delaying MyDatabaseId which is what the backend uses to update the database-level pgstat entries. -- Michael --7q0qDqfH2O9te2Gs Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmSLwc4ACgkQnvQgOdby QH14YQ//dtpbXWJo6nFCUme/gjsex1m4E+3tDxI66YKXKUPS4crKIFPzSxylkUFU 9YskllHdIBv/QUK58aNPiyteWJTS37yXBsjgcbBjNd/8poXL4Tj8Glv13sO4GtHX sTCI128uMYHEMod+caWZW+72bPyFna9pmuHCfARRJve4otUPyKFO16JnLpPsnyJC CaRkEAeg1GseM3iWn4SN4IDKkDqHpjTJtKHEojjNKOUFXGGMHN+ejxIbhCNsPZ6S TQjlZIe0Mv9nnPIY+LB16eL5TzwK20qkLRBQg6DZ73JH/dnW8trwmLWu/0ZBxWqE g8C9/HIxyqGKWF3IiQovjrnCKBCfLoV8E5WrzDOXbAw1lGRKwgJ6rwrKLH8mt2U3 /6WVrQFZEWrLAsWbtG3MIC+Sb8wGKaGLBfaBvYzdtTuoVgR37OJVg55Z5/mFlyQa dafXaPo3i4pfEMfb+0Y5hzuzGoBwroLlTsgpsL+4L0Baf5ViuWZezJFk77deO6kg 9BGlUlP3JN8auJxV9LHbEUUa1+Q60WswFsHzsgYfnyBqAKEY8cAxAfqvppa+tTXN gVRPJxeY6eH/G0WkOVw1r8LecQB9qQHNUMQVHl8s8YujVGvleSw/ZwCD06B4v7Uv GgqADzNz1WnBVL+CB/YchEjw1995AhWNlU1dJX87/jfhV9sXKMo= =akTa -----END PGP SIGNATURE----- --7q0qDqfH2O9te2Gs--