pg_stat_activity
というテーブルに入っているようです。 datname
でデータベース単位で絞り込めます。
$ echo '\pset pager off \\ select pid, usename, datname, application_name, client_addr, client_hostname, state, query from pg_stat_activity where datname = '\''some_database'\'';' | psql postgres Pager usage is off. pid | usename | datname | application_name | client_addr | client_hostname | state | query -------+-----------+---------------+--------------------------------------------------------------+--------------+-----------------+-------+-------------------------------------------------------------------------------- 16082 | some_user | some_database | unicorn worker[0] -E production -p 5000 -c config/unicorn.rb | xx.xx.xxx.xx | | idle | SELECT COUNT(*) FROM "some_table" WHERE "some_table"."type" IN ('SomeType') 16326 | some_user | some_database | unicorn worker[1] -E production -p 5000 -c config/unicorn.rb | xx.xx.xxx.xx | | idle | SELECT COUNT(*) FROM "some_table" (2 rows)