如何查看活动查询底层游标

Lor*_*rin 7 postgresql

pg_stat_activity我可以看到客户端正在使用游标通过一些查询结果.但是我如何才能看到原始查询是什么?

pipeline=> select pid, query from pg_stat_activity where state = 'active' order by query_start;
  pid  |                                                         query
-------+--------------------------------------------------------------------------------------
  6734 | FETCH FORWARD 1000 FROM "c_109886590_1"
 26731 | select pid, query from pg_stat_activity where state = 'active' order by query_start;
(2 rows)
Run Code Online (Sandbox Code Playgroud)

我看到了pg_cursors,但它是空的:

pipeline=> select * from pg_cursors;
 name | statement | is_holdable | is_binary | is_scrollable | creation_time
------+-----------+-------------+-----------+---------------+---------------
(0 rows)
Run Code Online (Sandbox Code Playgroud)

服务器位于AWS RDS上.

pipeline=> select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.3.3 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2), 64-bit
(1 row)
Run Code Online (Sandbox Code Playgroud)

Cra*_*ger 9

你不能.

pg_cursors是后端本地的.它不显示不属于当前连接的游标.

PostgreSQL无法找出哪个查询是来自另一个会话的游标的基础.

我能想到的唯一方法是使用日志分析,log_statement = all并使用合适的方法log_line_prefix.