如何分析 PostgreSQL 数据库?
我想分析(密切关注)PostgreSQL 数据库中发生的所有活动。
有没有这样的实用程序可以帮助我做到这一点?
I want to profile (keep an Eye on) all the activities that goes on in a Database which is in PostgreSQL.
Is there any such utility which will help me do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在我看来,“关注”和“剖析”是两个截然不同的任务。
对于分析(不是实时查看当前正在发生的情况,而是查看哪些查询花费最多时间等),请查看 pgFouine:
http://pgfouine.projects.postgresql.org/
这将让您了解哪些查询是资源密集型的,并采取适当的操作:添加缺少的索引、使用其他技术重写查询等。
"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:
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.
为了“保持警惕”,我使用 pgtop,一个故意模仿 Unix 'top' 命令的程序。
For "keeping an eye", I use pgtop, a program which deliberately mimics Unix 'top' command.
PgBadger 是一个积极维护的分析工具,提供非常详细的报告和图表 (查看示例)。 它可以处理大量 PostgreSQL 日志来回答问题,例如:
(PgBadger 的明确构建目的是“取代并超越”pgFouine,后者自 2010 年左右以来就不再维护。)
PgBadger is an actively maintained profiling tool that provides very detailed reports and graphs (see examples). It can process large volumes of PostgreSQL logs to answer questions like:
(PgBadger was explicitly built to "replace and outperform" pgFouine, which has not been maintained since about 2010.)
好吧,如果你正在查看发生了什么,关于选择、更新、删除等,
pg_catalog
架构中有一些视图,我主要使用pg_stat_user_tables
和pg_stat_user_indexes
但还有更多,都在pg_stat*
内。还有
pg_stat_activity
视图,它告诉您服务器上当前正在运行的内容。我已经将四个使用 user_tables 和 user_indexes 的 munin 插件组合在一起,它们可以那里
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 usepg_stat_user_tables
andpg_stat_user_indexes
but there are many more, all withinpg_stat*
.There also is the
pg_stat_activity
view which tells you what's running on your server right now.I've hacked together four munin plugins that uses the user_tables and user_indexes, they're available there
查看 Nagios-Plugin 脚本 或 check_postgres.pl
Have a look at Nagios-Plugin script or check_postgres.pl