O'Reilly logo

PostgreSQL 9 Administration Cookbook by Hannu Krosing, Simon Riggs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What are they running?

Here we show how to check what query is currently running.

Getting ready

Make sure that you are logged in as a superuser or as the same database user you want to check.

Make sure that the parameter track_activities = on is set.

This can be done either in the postgresql.conf file or by the superuser using the following SQL statement:

SET track_activities = on

How to do it...

To see what all connected users are running now, just run the following:

SELECT datname,usename,current_query FROM pg_stat_activity ;

On systems with a lot of users, you may notice that the majority of backends are running a weird query<IDLE>. This denotes the state, where no query is actually running, and PostgreSQL is waiting for new commands from the user. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required