Re: pg_stat_statements -- Historical Query

From: Julien Rouhaud <rjuju123(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: anand086 <anand086(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: pg_stat_statements -- Historical Query
Date: 2017-08-10 07:30:54
Message-ID: CAOBaU_btxHb03OW8gnzDdGWkPBXUpuJKcyck92gp6jqvzYE4eA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Aug 10, 2017 at 6:41 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Aug 10, 2017 at 6:23 AM, anand086 <anand086(at)gmail(dot)com> wrote:
>> I was looking for a way to maintain historical query details in Postgres to
>> answer questions like
>>
>> What was the sql call rate between time X and Y?
>> Did the execution count increase for the query increase between time X and
>> Y?
>> In past 10mins what all queries were run in the db?
>>
>> and few others like this.
>>
>> What would be best way to do it? Any thoughts?
>
> pg_stat_statements has a function allowing to reset what the view
> pg_stat_statements holds as information. You could copy periodically
> the data of pg_stat_statements and then invoke
> pg_stat_statements_reset to put everything back to zero. Then you
> would just need to do your analysis work based on the amount of data
> copied into your custom table.

You can also use powa-archivist extension which does the aggregation,
data retention and so on with a bgworker:
https://github.com/dalibo/powa-archivist.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Poty 2017-08-10 07:37:43 foreign key with char and varchar
Previous Message Michael Paquier 2017-08-10 04:41:46 Re: pg_stat_statements -- Historical Query