Here we will show you how to check which query is currently running.
You have to make sure that you are logged in as a superuser or as the same database user you want to check. Also, ensure that the parameter track_activities = on is set (which it normally should be, being the default setting). If not, check the Updating the parameter file recipe in Chapter 3, Configuration.
To see which connected users are running at this moment, just run the following:
SELECT datname, usename, state, query