是否有相当于 SQL Server 分析器的 PostgreSQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2430380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a PostgreSQL equivalent of SQL Server profiler?
提问by BozoJoe
I need to see the queries submitted to a PostgreSQL server. Normally I would use SQL Server profiler to perform this action in SQL Server land, but I'm yet to find how to do this in PostgreSQL. There appears to be quite a few pay-for tools, I am hoping there is an open source variant.
我需要查看提交给 PostgreSQL 服务器的查询。通常我会使用 SQL Server 分析器在 SQL Server 环境中执行此操作,但我还没有找到如何在 PostgreSQL 中执行此操作。似乎有很多付费工具,我希望有一个开源变体。
采纳答案by Joshua Smith
You can use the log_statement config setting to get the list of all the queries to a server
您可以使用 log_statement 配置设置来获取服务器的所有查询列表
https://www.postgresql.org/docs/current/static/runtime-config-logging.html#guc-log-statement
https://www.postgresql.org/docs/current/static/runtime-config-logging.html#guc-log-statement
Just set that, and the logging file path and you'll have the list. You can also configure it to only log long running queries.
只需设置它,以及日志文件路径,您就会拥有列表。您还可以将其配置为仅记录长时间运行的查询。
You can then take those queries and run EXPLAIN on them to find out what's going on with them.
然后,您可以接受这些查询并对它们运行 EXPLAIN 以了解它们发生了什么。
https://www.postgresql.org/docs/9.2/static/using-explain.html
https://www.postgresql.org/docs/9.2/static/using-explain.html
回答by vladr
Adding to Joshua's answer, to see which queries are currently runningsimply issue the following statement at any time (e.g. in PGAdminIII's query window):
添加到 Joshua 的答案中,要查看当前正在运行的查询,只需随时发出以下语句(例如,在 PGAdminIII 的查询窗口中):
SELECT datname,procpid,current_query FROM pg_stat_activity;
Sample output:
示例输出:
datname | procpid | current_query
---------------+---------+---------------
mydatabaseabc | 2587 | <IDLE>
anotherdb | 15726 | SELECT * FROM users WHERE id=123 ;
mydatabaseabc | 15851 | <IDLE>
(3 rows)
回答by Giovanni Porcari
I discovered pgBadger (http://dalibo.github.io/pgbadger/) and it is a fantastic tool that saved my life many times. Here is an example of report: http://dalibo.github.io/pgbadger/samplev4.html. If you open it and go to 'top' menu you can see the slowest queries and the time consuming queries. Then you can ask details and see nice graphs that show you the queries by hour and if you use detail button you can see the SQL text in a pretty form. So I can see that this tool is free and perfect.
我发现了 pgBadger ( http://dalibo.github.io/pgbadger/),它是一个很棒的工具,多次救了我的命。这是一个报告示例:http: //dalibo.github.io/pgbadger/samplev4.html。如果您打开它并转到“顶部”菜单,您可以看到最慢的查询和耗时的查询。然后,您可以询问详细信息并查看按小时显示查询的精美图表,如果您使用详细信息按钮,您可以以漂亮的形式查看 SQL 文本。所以我可以看到这个工具是免费和完美的。