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 1sAE53-008LGE-R9 for pgsql-admin@arkaria.postgresql.org; Thu, 23 May 2024 19:26:27 +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 1sAE53-00FYhU-Gh for pgsql-admin@arkaria.postgresql.org; Thu, 23 May 2024 19:26:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sAE53-00FYfG-4i for pgsql-admin@lists.postgresql.org; Thu, 23 May 2024 19:26:25 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sAE50-000QTG-78 for pgsql-admin@lists.postgresql.org; Thu, 23 May 2024 19:26:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 44NJQIb2463821; Thu, 23 May 2024 15:26:18 -0400 From: Tom Lane To: Holger Jakobs cc: pgsql-admin@lists.postgresql.org Subject: Re: query execution time for last 24 hours in PostgreSQL In-reply-to: References: Comments: In-reply-to Holger Jakobs message dated "Thu, 23 May 2024 21:05:13 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <463819.1716492378.1@sss.pgh.pa.us> Date: Thu, 23 May 2024 15:26:18 -0400 Message-ID: <463820.1716492378@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Holger Jakobs writes: > Am 23.05.24 um 20:07 schrieb nikhil kumar: >> Can you please let me know anyone how to get each query execution time >> from last 24 hours in PostgreSQL > pg_stat_activity shows current activity, not historic activity. > Unless you use an extension like pg_stat_statements, or log your > statements, the information won't be available. pg_stat_statements only collects cumulative runtime. The OP seems to be asking for the runtime of each execution of each statement. The only way to get that is by logging the durations (see log_duration and related settings) and then scraping the postmaster log. You might want to use pgbadger or a similar tool to help with the scraping and subsequent data analysis. regards, tom lane