我需要查看提交到PostgreSQL服务器的查询。通常我会使用SQL Server profiler在SQL Server平台上执行此操作,但我还不知道如何在PostgreSQL中执行此操作。似乎有相当多的付费工具,我希望有一个开源的变体。
发布于 2010-03-12 03:51:21
您可以使用log_statement配置设置来获取服务器的所有查询列表
https://www.postgresql.org/docs/current/static/runtime-config-logging.html#guc-log-statement
只需设置它和日志文件路径,您就会得到该列表。您还可以将其配置为仅记录长时间运行的查询。
然后,您可以获取这些查询,并对它们运行EXPLAIN,以找出它们发生了什么。
https://www.postgresql.org/docs/9.2/static/using-explain.html
发布于 2010-03-12 06:12:33
除了Joshua的回答,要查看which queries are currently running,只需在任何时候(例如,在PGAdminIII的查询窗口中)发出以下语句:
SELECT datname,procpid,current_query FROM pg_stat_activity;
示例输出:
datname | procpid | current_query
---------------+---------+---------------
mydatabaseabc | 2587 | <IDLE>
anotherdb | 15726 | SELECT * FROM users WHERE id=123 ;
mydatabaseabc | 15851 | <IDLE>
(3 rows)
发布于 2014-02-13 07:19:25
我发现了pgBadger (http://dalibo.github.io/pgbadger/),它是一个神奇的工具,多次救了我的命。这里有一个报告的例子:http://dalibo.github.io/pgbadger/samplev4.html。如果你打开它并进入“顶部”菜单,你可以看到最慢的查询和耗时的查询。然后,您可以询问详细信息并看到按小时显示查询的漂亮图形,如果您使用详细信息按钮,您可以看到漂亮形式的SQL文本。所以我可以看到这个工具是免费和完美的。
https://stackoverflow.com/questions/2430380
复制