Here we show how to check what query is currently running.
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
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
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. ...