如何分析 PostgreSQL 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/365103/
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
How to profile PostgreSQL Database?
提问by Yogi Yang 007
I want to profile (keep an Eye on) all the activities that goes on in a Database which is in PostgreSQL.
我想分析(密切关注)PostgreSQL 中数据库中发生的所有活动。
Is there any such utility which will help me do this?
有没有这样的实用程序可以帮助我做到这一点?
采纳答案by bortzmeyer
回答by rebra
"Keep an eye on" and "profile" are two quite different tasks in my view.
在我看来,“密切关注”和“个人资料”是两个完全不同的任务。
For profiling (not a live view on what's going on right now, but to see which queries take most time etc), check out pgFouine:
对于分析(不是实时查看当前正在发生的事情,而是查看哪些查询花费最多时间等),请查看 pgFouine:
http://pgfouine.projects.postgresql.org/
http://pgfouine.projects.postgresql.org/
This will let you see which queries are resource intensive, and take appropriate action: Add missing indexes, rewrite queries using other techiques etc.
这将让您查看哪些查询是资源密集型的,并采取适当的措施:添加缺失的索引、使用其他技术重写查询等。
回答by L. G.
Since rebra answer another profiling tool pgbadger
went out.
You can find it here:
http://dalibo.github.io/pgbadger/
由于 rebra answer 另一个分析工具pgbadger
消失了。你可以在这里找到它:http:
//dalibo.github.io/pgbadger/
you can get a very detailed report and graphs.
您可以获得非常详细的报告和图表。
pgfouine is not maintained anymore, last update was in 2010.
pgfouine 不再维护,上次更新是在 2010 年。
回答by mat
Well, if you're looking at what's going on, regarding selects, updates, deletes, and so on, there are a few views in the pg_catalog
schema, I mainly use pg_stat_user_tables
and pg_stat_user_indexes
but there are many more, all within pg_stat*
.
好吧,如果您正在查看正在发生的事情,关于选择、更新、删除等,pg_catalog
模式中有一些视图,我主要使用pg_stat_user_tables
,pg_stat_user_indexes
但还有更多,都在pg_stat*
.
There also is the pg_stat_activity
view which tells you what's running on your server right now.
还有一个pg_stat_activity
视图可以告诉您现在服务器上正在运行什么。
I've hacked together four munin plugins that uses the user_tables and user_indexes, they're available there
我已经破解了四个使用 user_tables 和 user_indexes 的 munin 插件,它们在那里可用
回答by Patryk Kordylewski
Have a look at Nagios-Plugin scriptor check_postgres.pl