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 1tLbBb-00Fng4-Sb for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Dec 2024 04:52:28 +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 1tLbBZ-00745Q-82 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Dec 2024 04:52: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.94.2) (envelope-from ) id 1tLbBX-00745H-US for pgsql-hackers@lists.postgresql.org; Thu, 12 Dec 2024 04:52:26 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLbBS-002Nvx-AW for pgsql-hackers@lists.postgresql.org; Thu, 12 Dec 2024 04:52:23 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id E9B6E1383EA3; Wed, 11 Dec 2024 23:52:16 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Wed, 11 Dec 2024 23:52:16 -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=fm1; t=1733979136; x=1734065536; bh=M8qf+cv6S8 WSvY+Quspvypu6QaRJExrwcvEigekbdE0=; b=QIu1yEFNhArAsJHrrvOxt2iFfL +y8xDSZyrKdg5wI04W1KhI0yhJ+VBt2kpnL7tqIEkq3plsgEy8yAd1ClBGWnoT5r 5EnJqAadZ7UecDxmpBX6UcRvjF6pPhm87T5q1MESjrcHNhLfPH7id8wyqN365wyZ xqjT+4JesibZA6GVJYcRIKsUBB/cmBTKUjNsM3A09ePTcKJC9J6jtNY7MRJIDUnp Xb+5BfXELXxTXOTcw8II+jpRZgJyT/Zbi7fgLABVC+L0WlfMqUSAHKzuyg6FgwCv 2zfadsF65zHkFsORcPJBu3052PVbEl6VFxxdjSjK/8rTVikKHgjF3DAZX2RA== 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=fm1; t= 1733979136; x=1734065536; bh=M8qf+cv6S8WSvY+Quspvypu6QaRJExrwcvE igekbdE0=; b=LhoWoWNSrHLl4nYqUrXbYz7FqDDl8YYwu3RjP0cAIiDJsNPzZBk uCxlmuWfwBi27WA7an7TyzWRcg6u6C3HTVJ0z9VPKWISXorGDmAHI5+j5hwqviks XP+HFSgZa5BOGfeVYzBlqAnAn4wOMP8SQrDfKaYrWghhiLjxgVbyvMPtOU2rP7NQ DqYrvLgJ09Nn71sNaiQTitD2c2YZ6gplKCiHxctBpVtSXsginYG7guBIAAN3ok+t Vp6q0wMNk4wEx+bJOqsmGH8XI2YcsG3ELkI9qOROJLDz0KgOd9G2JLSq0YN6DbNy l8gxFZIrvdZOekTOOBHjJim1SV1gR6aI1KQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeefgddvtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhgg tggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoe hmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleei fedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehp rghquhhivghrrdighiiipdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuth dprhgtphhtthhopegsvghrthhrrghnuggurhhouhhvohhtrdhpghesghhmrghilhdrtgho mhdprhgtphhtthhopegshigrvhhuiiekudesghhmrghilhdrtghomhdprhgtphhtthhope grlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhrtghpthhtohephhhorhhi khihohhtrgdrnhhtthesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhhrg gtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 11 Dec 2024 23:52:14 -0500 (EST) Date: Thu, 12 Dec 2024 13:52:03 +0900 From: Michael Paquier To: Bertrand Drouvot Cc: Nazir Bilal Yavuz , Alvaro Herrera , Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org 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="8FQr48JqJw73SR9H" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --8FQr48JqJw73SR9H Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 25, 2024 at 03:47:59PM +0000, Bertrand Drouvot wrote: > =3D=3D=3D Remarks >=20 > R1: as compared to v5, v6 removes the per-backend I/O stats reset from=20 > pg_stat_reset_shared(). I think it makes more sense that way, since we are > adding pg_stat_reset_single_backend_io_counters(). The per-backend I/O st= ats > behaves then as the subscription stats as far the reset is concerned. Makes sense to me to not include that in pg_stat_reset_shared(). > R2: as we can't merge the flush cb anymore, only the patches related to > the stats_fetch_consistency/'snapshot' are missing in v6 (as compared to = v5). > I propose to re-submit them, re-start the discussion once 0001 goes in. Yeah, thanks. I should think more about this part, but I'm still kind of unconvinced. Let's do things step by step. For now, I have looked at v6. + view. The function does not return I/O statistics for the checkpoi= nter, + the background writer, the startup process and the autovacuum laun= cher + as they are already visible in the pg_stat_io + view and there is only one of those. This last sentence seems unnecessary? The function is named "backend", and well, all these processes are not backends. + /* + * Maybe an auxiliary process? That should not be possible, due to + * pgstat_tracks_per_backend_bktype() though. + */ + if (proc =3D=3D NULL) + proc =3D AuxiliaryPidGetProc(backend_pid); [...] + /* + * Maybe an auxiliary process? That should not be possible, due to + * pgstat_tracks_per_backend_bktype() though. + */ + if (proc =3D=3D NULL) + proc =3D AuxiliaryPidGetProc(pid); This does not seem right. Shouldn't we return immediately if BackendPidGetProc() finds nothing matching with the PID? + /* Look for the backend type */ + for (curr_backend =3D 1; curr_backend <=3D num_backends; curr_backend++) + { + LocalPgBackendStatus *local_beentry; + PgBackendStatus *beentry; + + /* Get the next one in the list */ + local_beentry =3D pgstat_get_local_beentry_by_index(curr_backend); + beentry =3D &local_beentry->backendStatus; + + /* looking for specific PID, ignore all the others */ + if (beentry->st_procpid !=3D pid) + continue; + + bktype =3D beentry->st_backendType; + break; + } Sounds to me that the backend type is not strictly required in this function call if pg_stat_activity can tell already that? + (void) pgstat_per_backend_flush_cb(entry_ref, nowait); I'd recommend to not directly call the callback, use a wrapper function instead if need be. pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_= op, instr_time start_time, uint32 cnt) { + if (track_io_timing) Noise diff. /* - * Simpler wrapper of pgstat_io_flush_cb() + * Simpler wrapper of pgstat_io_flush_cb() and pgstat_per_backend_flush_cb= (). */ void pgstat_flush_io(bool nowait) This is also called in the checkpointer and the bgwriter and the walwriter via pgstat_report_wal(), which is kind of useless. Perhaps just use a different, separate function instead and use that where it makes sense (per se also the argument of upthread that backend stats may not be only IO-related..). Sounds to me that PgStat_BackendPendingIO should be PgStat_BackendPendingStats? +{ oid =3D> '8806', descr =3D> 'statistics: per backend IO statistics', + proname =3D> 'pg_stat_get_backend_io', prorows =3D> '5', proretset =3D> = 't', Similarly, s/pg_stat_get_backend_io/pg_stat_get_backend_stats/? + descr =3D> 'statistics: reset collected IO statistics for a single backe= nd', + proname =3D> 'pg_stat_reset_single_backend_io_counters', provolatile =3D= > 'v',=20 And here, pg_stat_reset_backend_stats? #define PGSTAT_KIND_SUBSCRIPTION 5 /* per-subscription statistics */ +#define PGSTAT_KIND_PER_BACKEND 6=20 Missing one comment here. FWIW, I'm so-so about the addition of pg_my_stat_io, knowing that pg_stat_get_backend_io(NULL/pg_backend_pid()) does the same job. I would just add a note in the docs with a query showing how to use it with pg_stat_activity. An example with LATERAL, doing the same work: select a.pid, s.* from pg_stat_activity as a, lateral pg_stat_get_backend_io(a.pid) as s where pid =3D pg_backend_pid(); -- Michael --8FQr48JqJw73SR9H Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmdaa/MACgkQnvQgOdby QH3BbRAAjZTcNUWcXprtCVuOc8HZHuwjIp1zHayhDlqtB2buD1Dr5H5HVT/S42TK rdxOe7AI8yEq1wer/6QH3hWNj7nVnfP61Vw9Sh+Qst6Mgw/9Y0KSg5LiOhC8pPRY 66XlVPF+jv2oLelrIDbR40/54WX6lNw60MdvpCu/CMFAISWaKkyR2t29cRl5Kue8 KX+LGnZPLAWqu6RKEcXCkGl8+WHEdVzi7dsZxLvaMZb/Z34/UKyiUnX1o7tBVU91 8FX6bt+YFB+fu15GT69hJIKnxZLBqwvSOQodKqzzEOlqXC3AV+bYwWbPuYAWx9V9 L79M59zPciyIFpSep57rHwzopdHl2momt6R3u4HXyiaKyhppjx3UXyYL11IaGjHr td8JZ4l94HNqCIGufCv8xzwLEeFT0SOmU0kwimyXhLYZZK4PNsF5m/qTpIkYDMZB 4E5+n1zznVkqMz+MT/qDEghI+HgB/Qq/NBaSUEo7ss5FCfoJ+TF2lyuvpkVxmXLJ 2t9rMgUh1Qxdk7OZCEV6NyNZrMbI6zkLXl5mfmuRidoyFBVXhYJ8i9M22ggevh2I l8YOdfT/Ad9yVIDGNmkBXzYxJVyTtTSSlSgreo2S+OpmDvF3dUNn7C09tF/tpQ9y WCdq4bcCKdLtLseTKKua2oIlNw3/1EFn6mJgOwwhn9VohKJQ96o= =hruS -----END PGP SIGNATURE----- --8FQr48JqJw73SR9H--