How to check the contents of a prepared statement in the pg_stat_activity.query field

I am currently checking a long query in PostgreSQL.

To verify this, I requested the following command:

SELECT pid, waiting, query_start, substr(query, 0, 50)
FROM pg_stat_activity
ORDER BY query_start
LIMIT 30;

And I get:

  pid  | waiting |          query_start          |                              substr
-------+---------+-------------------------------+------------------------------------------------------------------
 26797 | f       | 2015-07-06 12:44:04.418403+00 | SELECT * FROM "projects" WHERE "projects"."id" = $1 LIMIT 1
 ...

To parse this long query, I want to check the contents of $1this prepared statement.

Is there any way to get this?

+4
source share
1 answer

You will not get this information from pg_stat_activity, but you can get the full request from the slow query log.

+1
source

All Articles