App to monitor PostgreSQL queries in real time?

前端 未结 4 2018
小蘑菇
小蘑菇 2021-02-03 23:31

I\'d like to monitor the queries getting sent to my database from an application. To that end, I\'ve found pg_stat_activity, but more often then not, the rows which

4条回答
  •  无人及你
    2021-02-04 00:11

    With PostgreSQL 8.4 or higher you can use the contrib module pg_stat_statements to gather query execution statistics of the database server.

    Run the SQL script of this contrib module pg_stat_statements.sql (on ubuntu it can be found in /usr/share/postgresql//contrib) in your database and add this sample configuration to your postgresql.conf (requires re-start):

    custom_variable_classes = 'pg_stat_statements'
    pg_stat_statements.max = 1000
    pg_stat_statements.track = top # top,all,none
    pg_stat_statements.save = off
    

    To see what queries are executed in real time you might want to just configure the server log to show all queries or queries with a minimum execution time. To do so set the logging configuration parameters log_statement and log_min_duration_statement in your postgresql.conf accordingly.

提交回复
热议问题