Using this recipe, we will get all the current running SQL commands from the PostgreSQL instance.
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.
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...