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 1tYEAS-006GCp-Vp for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 00:55:29 +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 1tYEAR-002deK-Ii for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Jan 2025 00:55:28 +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 1tYEAR-002deC-5N for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 00:55:27 +0000 Received: from fout-a3-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.96) (envelope-from ) id 1tYEAQ-000ce5-0F for pgsql-hackers@lists.postgresql.org; Thu, 16 Jan 2025 00:55:26 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id F231013802AA; Wed, 15 Jan 2025 19:55:24 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Wed, 15 Jan 2025 19:55:24 -0500 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=1736988924; x=1737075324; bh=eX0ECdG6GJ nV5fs74y2ApTMRqgG1uvGW0eOVwG62i+o=; b=o/++FISFReV4evcr6TUVMeJn7L /Rba+OFq+SDKNHCzd60+145QgLUNl+uBrpdUVdy9mvgzFEPx3iGnWfnmW9Zygo59 ejQ4a/BZjEDzR5fQsvQZwh4EEKD2oiHxBm+6lCfLz3jg79JdFU7JHarDCpS+ZGkk rzPXoDiyswETLPoVua806XgRTt7qjaQizZZYWt0/GWQiEEL0dMMUvvAaaL/1NPPI 6xxz0LiFyJOIZvWncor2dafVmRL4a4Y2lXK5gsAmsfHFRI7qfgYBKiux3jPfjJUe b0mAIMoR3sn4P21YqBjwl9skkEI1rzHSyMKW/1pb5KHlnJo/5PNhRgk56b9A== 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-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1736988924; x=1737075324; bh=eX0ECdG6GJnV5fs74y2ApTMRqgG1uvGW0eO VwG62i+o=; b=rSP6YaaR/ROtHUtnAKFfhP/Il0f+V2hHEdDR9etfVl1Bd29kZdU NgheT1RRxe6VR7UZlyk0nWE02XuKqCxATInPpZt1zFUDiH8NMQKZlhVRpHbx57CD jJKfIPCI4/DrAVuhlKZ9vSOh5aDL/r5HY2DmF6QqQ2O0aR1c9IiMGj+8PyxLvc1I dyTR8kLEhjjyydHwIDB/35z6GGL2F9gAP04TGyhcsK77ERTvoOvvTNQWELzd5G94 xF5rvuEUTSvypgiqJZf+pefA25TLkJLmhqJtSvnjzUkpj6PK2C2bjyu1cQJ5P926 BtRvkiT5SadKEALC2yGCeDyiAhNmhhQraNg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudeitddgvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteel ieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtohepsgihrghvuhiikedusehgmhgrihhlrdgtohhmpdhrtghpthhtohep sggvrhhtrhgrnhguughrohhuvhhothdrphhgsehgmhgrihhlrdgtohhmpdhrtghpthhtoh eprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdprhgtphhtthhopehhohhr ihhkhihothgrrdhnthhtsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhh grtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohep rghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jan 2025 19:55:22 -0500 (EST) Date: Thu, 16 Jan 2025 09:55:10 +0900 From: Michael Paquier To: Nazir Bilal Yavuz Cc: Bertrand Drouvot , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org, Andres Freund Subject: Re: per backend I/O statistics Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="dJ42aCNBiJKeL8rK" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --dJ42aCNBiJKeL8rK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 15, 2025 at 05:20:57PM +0300, Nazir Bilal Yavuz wrote: > I think allowing only pgStatPendingContext to have > MemoryContextAllowInCriticalSection() is not enough. We need to allow > at least pgStatSharedRefContext as well to have > MemoryContextAllowInCriticalSection() as it can be allocated too. >=20 > ''' > pgstat_prep_pending_entry() -> > pgstat_get_entry_ref() -> > pgstat_get_entry_ref_cached() -> > MemoryContextAlloc(pgStatSharedRefContext, sizeof(PgStat_EntryRef)) > ''' Yep, I was pretty sure that we have a bit more going on. Last time I began digging into the issue I was loading injection_points in shared_preload_libraries with stats enabled to see how much I could break, and this was one pattern once I've forced the pending part. I didn't get through the whole exercise. > While doing the initdb, we are restoring stats with the > pgstat_restore_stats() and we do not expect any pending stats. The > problem goes like that: >=20 > ''' > pgstat_restore_stats() -> > pgstat_read_statsfile() -> > pgstat_reset_after_failure() -> > pgstat_drop_all_entries() -> > pgstat_drop_entry_internal() -> > We have an assertion there which checks if there is a pending stat entry: >=20 > /* should already have released local reference */ > if (pgStatEntryRefHash) > Assert(!pgstat_entry_ref_hash_lookup(pgStatEntryRefHash, shent->k= ey)); > ''' You mean that this is not something that happens on HEAD, but as an effect of trying to add WAL stats to pg_stat_io, right? > I was a bit surprised that Bertrand did not encounter the same problem > while working on the 'per backend WAL statistics' patch. Then I found > the reason, it is because this problem happens only for WAL read and > WAL init IOs which are starting to be tracked in my patch. By saying > that, I could not decide which thread to write about this problem, > migrating WAL stats thread or this thread. Since this thread is active > and other stats may cause the same problem, I decided to write here. > Please warn me if you think I need to write this to the migrating WAL > stats thread. I'd rather treat that on a separate thread (please add me in CC if I'm not there yet!). I am OK to discuss any issues related to backend statistics here if HEAD is impacted based on how the feature is limited currently now, though. Another, simpler, idea would be to force more calls pgstat_prep_backend_pending() where this is problematic, like before entering a critical section when generating a WAL record. I am not sure that it would take care of everything, as you mention; that would leave some holes depending on the kind of interactions with the pgstats dshash we do in these paths. -- Michael --dJ42aCNBiJKeL8rK Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmeIWO4ACgkQnvQgOdby QH0PwhAAprM9S2GN3fAHzlPKlyZ9UztFSmQLBTX3LlDft7K4947AngSy4ELMPW87 e3JcM9N9efZ7ozHGp5Yjn+m2ZHD5/NwJXfnDy4J9WFzLqqojIHpmmIeFurj4g5PE EcEI2qwWI2bHMATQNJ9GpsXroiEl/20RgkQu89vkl/upyYsEiYZBPTRwrcpNt5dx bnH0klvoGUCsUaV81zkN+Lf6AvUngRAetPSrpD3N9BVQMrAZ4IHlMdQ9tLflQ6k3 s3SwIBAn8n0CpkAeaybwRw0+Lr0Z0U+NIt57Mixg/ktdZgYpAZmI2KnJWz2/o7ZP 4oRcwlGKDEiAvsAXm1nXxtiSS0lkgKeAdSZSm22+SN0Bu32S8o68ZA40dn3ms/h/ YpXv2SNnHrMr0WiMASTTpozrTxq7YkuFxTjdi3VSPKl0MV4uT9Lnb9N0h5t9eeWP O0cv/d8Cqd0d5Vbmkeht4i9xaRpzqpU+/bIPg5s0hE6i2FyFaOPbvxuU3ZE4Wfol vOoKk8j9LjRPTW42xz301IBzoc8kIyCMdxPjta9/0VosVVYP3qV+a+9mnEEG7Ud+ +N1ajXcJ9K4lbs02JDfniACbMIwWWMNeOiO38WQM5l55Zf93Ta7NLtw0cNfgjbOK zgZ7DSi4ZCmKopdnohiPRmJcEMjxytVvrwn0z4jC99qI8pCNY54= =0RKv -----END PGP SIGNATURE----- --dJ42aCNBiJKeL8rK--