pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Holger Jakobs <holger@jakobs.com>
To: pgsql-admin@lists.postgresql.org
Subject: Re: query execution time for last 24 hours in PostgreSQL
Date: Thu, 23 May 2024 21:05:13 +0200
Message-ID: <d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com> (raw)
In-Reply-To: <CACJRp483AWu5Jar4xt9y2wbdDq9Fsxqou6kaPLCs_ifC==902A@mail.gmail.com>
References: <CACJRp483AWu5Jar4xt9y2wbdDq9Fsxqou6kaPLCs_ifC==902A@mail.gmail.com>

Am 23.05.24 um 20:07 schrieb nikhil kumar:
> Hi Team,
>
> Can you please let me know anyone how to get each query execution time 
> from last 24 hours in PostgreSQL
>
> I tried the below query but giving the wrong information.
>
> SELECT sa.client_addr,
> sa.usename,
> sa.datname,
> sa.state,
> sa.query,
> sa.query_start,
> EXTRACT (EPOCH FROM (current_timestamp sa.query_start)) AS 
> execution_time_seconds
> FROM pg_stat_activity sa
> WHERE sa.query_start >= current_timestamp interval '24 hours';
>
> Thanks,
> Nikhil,
> PostgreSQL DBA,
> 8074430856.

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.

Regards,
Holger

-- 

Holger Jakobs, Bergisch Gladbach



Attachments:

  OpenPGP_signature (application/pgp-signature, 202B) download

view thread (4+ messages)  latest in thread

Message-ID: <d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com>
Permalink:  ../d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com/
Also on:    postgresql.org/message-id/d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: holger@jakobs.com, pgsql-admin@lists.postgresql.org
  Subject: Re: query execution time for last 24 hours in PostgreSQL
  In-Reply-To: <d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox