Will the pg_stat_statements view show old data if there is no transaction going?

  • Hi, I am trying to write a query using pg_stat_statements to find the elapsed time of queries running in the database. I want to know if there are no transactions in the database will the view show only the old data ? When will the data get purged from the view ? I want only those queries which was running in the past few minutes(suggest me an alternate view or any method to achieve this)....

    Thanks in advance....

  • this is not a Postgres site - you better off asking here https://www.postgresql.org/community/

  • If there are no transactions, it will only show the older data. There isn't an automatic rest of pg_stats_statements. However, there is a command you can issue to reset it if you want: pg_stats_statements_reset. So, if, for example, you release some new code, and you want to start measurements over from the start in order to see the changes in behavior, you can run pg_stats_statements_reset to get to zero on everything as outlined in the examples here. Just note in the documentation, this function isn't enabled universally and you do have to turn it on in order to have it available for use.

    And sure you can ask PostgreSQL questions here. It's why we have this section.

    Thanks for stopping by.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply