Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check content of prepared statement in pg_stat_activity.query field

Tags:

postgresql

Currently, I'm checking long running query in PostgreSQL.

To check this, I queried the command below:

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 analyse this long running query, I want to check the content of $1 of this prepared statement.

Are there any way to get this?

like image 502
Naoyoshi Aikawa Avatar asked Jul 07 '15 01:07

Naoyoshi Aikawa


People also ask

What is Pg_stat_activity in PostgreSQL?

pg_stat_activity is a system view that allows you to identify active SQL queries in AnalyticDB for PostgreSQL instances. The pg_stat_activity view shows a server process and its related session and query in each row.

What is Backend_xmin?

It is the backend's xmin horizon. That means that it is the oldest transaction ID whose effects may not be. visible to the transaction running in the backend. Since transaction IDs are stored in each row to determine its visibility, the minimum of the "backend_xmin" of all backends determines the cut-off.

How do you gather a table in statistics Postgres?

PostgreSQL Usage. Use the ANALYZE command to collect statistics about a database, a table or a specific table column. The PostgreSQL ANALYZE command collects table statistics which support generation of efficient query execution plans by the query planner.


1 Answers

You will not get this info from pg_stat_activity, but you may get the full query from slow query log.

like image 119
Boris Schegolev Avatar answered Oct 20 '22 07:10

Boris Schegolev