Skip to content

PostgreSQL Query Monitoring

postgres=# select * from pg_stat_activity;
 datid | datname  | procpid | usesysid | usename  | current_query |          query_start          |         backend_start         | client_addr | client_port
-------+----------+---------+----------+----------+---------------+-------------------------------+-------------------------------+-------------+-------------
 10793 | postgres |    3443 |       10 | postgres | <IDLE>        | 2009-02-15 07:36:14.272725-08 | 2009-02-15 07:36:14.272521-08 |             |          -1
(1 row)

If you do not have stats_command_string set to on in your postgresql.conf, you will see output similar to the following:

postgres=#  select * from pg_stat_activity;
 datid | datname  | procpid | usesysid |    usename    |        current_query         | query_start |         backend_start         | client_addr | client_port
-------+----------+---------+----------+---------------+------------------------------+-------------+-------------------------------+-------------+-------------
 10793 | postgres |    2275 |       10 | postgres      | <command string not enabled> |             | 2009-02-15 07:50:40.940629-08 |             |          -1
 16712 | isx      |   11447 |    16956 | rails_app0174 | <command string not enabled> |             | 2009-01-07 11:52:52.683856-08 | 172.16.1.4  |       44881
 16712 | isx      |    6037 |    16956 | rails_app0174 | <command string not enabled> |             | 2008-12-30 17:15:17.110313-08 | 172.16.1.4  |       37302
(3 rows)

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*