如何查看完整的阻止postgres查询?


9

我正在使用此页面上的语句来查看Postgres中的阻塞查询

SELECT bl.pid                 AS blocked_pid,
         a.usename              AS blocked_user,
         ka.query               AS blocking_statement,
         now() - ka.query_start AS blocking_duration,
         kl.pid                 AS blocking_pid,
         ka.usename             AS blocking_user,
         a.query                AS blocked_statement,
         now() - a.query_start  AS blocked_duration
  FROM  pg_catalog.pg_locks         bl
   JOIN pg_catalog.pg_stat_activity a  ON a.pid = bl.pid
   JOIN pg_catalog.pg_locks         kl ON kl.transactionid = bl.transactionid AND kl.pid != bl.pid
   JOIN pg_catalog.pg_stat_activity ka ON ka.pid = kl.pid
  WHERE NOT bl.granted;

但是查询被截断了,所以我通常看不到WHERE子句中的内容,这使得调试这些阻塞问题非常困难。有没有可以让postgres将完整查询记录到的设置pg_stat_activity

Answers:


11

跟踪查询的长度可以在参数中找到track_activity_query_size

18.8.1。查询和索引统计收集器

track_activity_query_size (integer)

为该pg_stat_activity.current_query字段指定保留的字节数,以跟踪每个活动会话的当前执行命令 。默认值为1024。该参数只能在服务器启动时设置。

例如,如果您已经track_activity_query_size=16384在配置中,那么这意味着将收集最多16k的查询文本。


1
只是为了确保它是明确的(如引文中所述,可能会被忽略)..更改该配置选项将需要重新启动服务器才能使其生效。
Joishi Bodio 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.