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 1qvdgs-006Lgv-Jl for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Oct 2023 13:12:54 +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 1qvdgr-003n3i-1z for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Oct 2023 13:12:53 +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 1qvdgq-003n3a-Og for pgsql-hackers@lists.postgresql.org; Wed, 25 Oct 2023 13:12:52 +0000 Received: from relay164.nicmail.ru ([91.189.117.8]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvdgn-002FAU-OL for pgsql-hackers@lists.postgresql.org; Wed, 25 Oct 2023 13:12:51 +0000 Received: from [10.28.138.152] (port=20530 helo=localhost) by relay.hosting.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1qvdgg-0002t8-Fl; Wed, 25 Oct 2023 16:12:43 +0300 Received: from [78.107.250.17] (account zubkov@moonset.ru HELO localhost) by incarp1104.mail.hosting.nic.ru (Exim 5.55) with id 1qvdgg-0002WK-2g; Wed, 25 Oct 2023 16:12:42 +0300 Received: from [192.168.61.131] by localhost with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvdVY-000Nhr-FE; Wed, 25 Oct 2023 16:12:42 +0300 Message-ID: <7599fe17eabde4e5b1256af63c05a72023132de7.camel@moonset.ru> Subject: Re: Add connection active, idle time to pg_stat_activity From: Andrei Zubkov To: Sergey Dudoladov , PostgreSQL Hackers Date: Wed, 25 Oct 2023 16:12:42 +0300 In-Reply-To: References: <20220201.135516.23011068590309830.horikyota.ntt@gmail.com> <20220322001335.x76b2htvnih2eofk@alap3.anarazel.de> <20221109015614.evw5egu7fansxj37@awork3.anarazel.de> <20221109023727.enmes3ab6gvr3zsq@awork3.anarazel.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-MS-Exchange-Organization-SCL: -1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Sergey, I've done a review of this patch. I found the patch idea very useful, thank you for the patch. I've noted something observing this patch: 1. Patch can't be applied on the current master. My review is based on application of this patch over ac68323a878 2. Being applied over ac68323a878 patch works as expected. 3. Field names seems quite long to me (and they should be uniformly named with the same statistics in other views. For example "running" term is called "active" in pg_stat_database) 4. Meaningless spaces at the end of line: - backend_status.c:586 - monitoring.sgml:5857 5. Patch adds usecs_diff =3D secs * 1000000 + usecs; at backend_status.c:pgstat_report_activity() to optimize calculations. But pgstat_count_conn_active_time((PgStat_Counter) secs * 1000000 + usecs); and =20 pgstat_count_conn_txn_idle_time((PgStat_Counter) secs * 1000000 + usecs); are left in place after that. 6. I'm not sure that I can understand the comment /* Keep statistics for pg_stat_database intact */ at backend_status.c:600 correctly. Can you please explain it a little? 7. Tests seems incomplete. It looks like we can check increments in all fields playing with transactions in tests. Also, I have a thought about other possible improvements fitting to this patch. The view pg_stat_session is really needed in Postgres but I think it should have much more statistics. I mean all resource statistics related to sessions. Every backend has instrumentation that tracks resource consumption. Data of this instrumentation goes to the cumulative statistics system and is used in monitoring extensions (like pg_stat_statements). I think pg_stat_session view is able to add one more dimension of monitoring - a dimension of sessions. In my opinion this view should provide resource consumption statistics of current sessions in two cumulative sets of statistics - since backend start and since transaction start. Such view will be really useful in monitoring of long running sessions and transactions providing resource consumption information besides timing statistics. regards, Andrei Zubkov Postgres Professional