如何查看PostgreSQL正在執行的SQL

 1,677 total views,  4 views today

今天在CPS伺服器上要找報表怎麼寫,因為要寫機器人自動產生報表的SQL,找了好久終於找到方法了。

先用報表軟體 故意下長一點的報表,這樣才有足夠的時間來抓SQL語法

2015-05-12_18h12_07

接下來按下查詢之後,趕快下底下的 SQL,就可以偷抓出他的SQL來用了

SELECT procpid,
start,
Now() - start AS lap,
current_query
FROM (SELECT backendid,
Pg_stat_get_backend_pid(S.backendid) AS procpid,
Pg_stat_get_backend_activity_start(S.backendid) AS start,
Pg_stat_get_backend_activity(S.backendid) AS current_query
FROM (SELECT Pg_stat_get_backend_idset() AS backendid) AS S) AS S
WHERE current_query <> ""
ORDER BY lap DESC;

執行結果:

2015-05-12_18h13_13

 

發表迴響

%d 位部落客按了讚: