Monday, November 26, 2007

Viewing current PostgreSQL Queries

I am a heavy MySQL user, so I constantly use a SHOW PROCESSLIST; to view how my developers or software are using the test database server. So now that we have more than one project using postgresql and since locking down the cpu is becoming more and more common I had to figure out a way to view the queries that are being executed on PostgreSQL.

I found this:

SELECT * FROM pg_stat_activity;


but since PostgreSQL turns off the storing of query strings all I could see was who where using the databse. So in the postgresql.conf file (in FreeBSD that's in /usr/local/pgsql/data/postgresql.conf) i just uncommented and edited the line with this option:

stats_command_string = true


Then just restart the postgresql and it is ready!