Re: query execution time for last 24 hours in PostgreSQL

From: Holger Jakobs <holger(at)jakobs(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: query execution time for last 24 hours in PostgreSQL
Date: 2024-05-23 19:05:13
Message-ID: d2f858b4-6699-649a-0c0a-ac0038c25d56@jakobs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2024-05-23 19:26:18 Re: query execution time for last 24 hours in PostgreSQL
Previous Message SOzcn 2024-05-23 18:25:21 Re: query execution time for last 24 hours in PostgreSQL