pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
query execution time for last 24 hours in PostgreSQL
4+ messages / 4 participants
[nested] [flat]

* query execution time for last 24 hours in PostgreSQL
@ 2024-05-23 18:07  nikhil kumar <nikhil.dba97@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: nikhil kumar @ 2024-05-23 18:07 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

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.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: query execution time for last 24 hours in PostgreSQL
@ 2024-05-23 18:25  SOzcn <selahattinozcnma@gmail.com>
  parent: nikhil kumar <nikhil.dba97@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: SOzcn @ 2024-05-23 18:25 UTC (permalink / raw)
  To: nikhil kumar <nikhil.dba97@gmail.com>; +Cc: pgsql-admin@lists.postgresql.org

Hello,

you can get this infos with pg_stat_statement extension.

https://www.postgresql.org/docs/current/pgstatstatements.html

nikhil kumar <nikhil.dba97@gmail.com>, 23 May 2024 Per, 21:08 tarihinde
şunu yazdı:

> 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.
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: query execution time for last 24 hours in PostgreSQL
@ 2024-05-23 19:05  Holger Jakobs <holger@jakobs.com>
  parent: nikhil kumar <nikhil.dba97@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Holger Jakobs @ 2024-05-23 19:05 UTC (permalink / raw)
  To: pgsql-admin@lists.postgresql.org

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:

  [application/pgp-signature] OpenPGP_signature (202B, ../../d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com/2-OpenPGP_signature)
  download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: query execution time for last 24 hours in PostgreSQL
@ 2024-05-23 19:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Holger Jakobs <holger@jakobs.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2024-05-23 19:26 UTC (permalink / raw)
  To: Holger Jakobs <holger@jakobs.com>; +Cc: pgsql-admin@lists.postgresql.org

Holger Jakobs <holger@jakobs.com> 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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2024-05-23 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-05-23 18:07 query execution time for last 24 hours in PostgreSQL nikhil kumar <nikhil.dba97@gmail.com>
2024-05-23 18:25 ` SOzcn <selahattinozcnma@gmail.com>
2024-05-23 19:05 ` Holger Jakobs <holger@jakobs.com>
2024-05-23 19:26   ` Tom Lane <tgl@sss.pgh.pa.us>

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