Finding out what the users are currently running
Using this recipe, we will get all the current running SQL commands from the PostgreSQL instance.
Getting ready
In the previous recipe, we discussed how to get all the active sessions information, and now we are going to get all the SQL statements that the active sessions are executing.
How to do it...
Initiate
pgbench
as aforementioned.Connect to the PostgreSQL database as either a superuser or database owner and execute the following SQL statement:
$ psql -h localhost -U postgres postgres=# SELECT datname, usename, application_name, now()-backend_start AS "Session duration", pid, query FROM pg_stat_activity WHERE state='active'; -[ RECORD 1 ]----+------------------------------- datname | postgres usename | postgres...