实时监控 PostgreSQL 查询的应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8597516/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:15:39  来源:igfitidea点击:

App to monitor PostgreSQL queries in real time?

postgresqlmonitoring

提问by Russell Christopher

I'd like to monitor the queries getting sent to my database from an application. To that end, I've found pg_stat_activity, but more often then not, the rows which are returned read " in transaction". I'm either doing something wrong, am not fast enough to see the queries come through, am confused, or all of the above!

我想监视从应用程序发送到我的数据库的查询。为此,我发现pg_stat_activity,但更常见的是,返回的行被读取为“在事务中”。我要么做错了什么,速度不够快,无法看到查询通过,我很困惑,或者以上所有!

Can someone recommend the most idiot-proof way to monitor queries running against PostgreSQL? I'd prefer some sort of easy-to-use UI based solution (example: SQL Server's "Profiler"), but I'm not too choosy.

有人可以推荐最愚蠢的方法来监视针对 PostgreSQL 运行的查询吗?我更喜欢某种易于使用的基于 UI 的解决方案(例如:SQL Server 的“Profiler”),但我并不太挑剔。

采纳答案by tscho

With PostgreSQL 8.4 or higher you can use the contrib modulepg_stat_statementsto gather query execution statistics of the database server.

使用 PostgreSQL 8.4 或更高版本,您可以使用contrib 模块pg_stat_statements来收集数据库服务器的查询执行统计信息。

Run the SQL script of this contrib module pg_stat_statements.sql(on ubuntu it can be found in /usr/share/postgresql/<version>/contrib) in your database and add this sample configuration to your postgresql.conf(requires re-start):

在您的数据库中运行此 contrib 模块的 SQL 脚本pg_stat_statements.sql(在 ubuntu 中可以在 中找到/usr/share/postgresql/<version>/contrib),并将此示例配置添加到您的postgresql.conf(需要重新启动):

custom_variable_classes = 'pg_stat_statements'
pg_stat_statements.max = 1000
pg_stat_statements.track = top # top,all,none
pg_stat_statements.save = off

To see what queries are executed in real time you might want to just configure the server log to show all queries or queries with a minimum execution time. To do so set the logging configuration parameterslog_statementand log_min_duration_statementin your postgresql.conf accordingly.

要查看实时执行哪些查询,您可能只想配置服务器日志以显示所有查询或具有最短执行时间的查询。为此,请相应地设置日志记录配置参数log_statementlog_min_duration_statement在您的 postgresql.conf 中。

回答by ertx

PgAdminoffers a pretty easy-to-use tool called server monitor

PgAdmin提供了一个非常易于使用的工具,称为服务器监视器

(Tools ->ServerStatus)

(工具 -> 服务器状态)

回答by Patrick

I haven't tried it myself unfortunately, but I think that pgFouine can show you some statistics.

不幸的是,我自己没有尝试过,但我认为 pgFouine 可以向您展示一些统计数据。

Although, it seems it does not show you queries in real time, but rather generates a report of queries afterwards, perhaps it still satisfies your demand?

虽然,它似乎并没有实时向您展示查询,而是在之后生成查询报告,也许它仍然满足您的需求?

You can take a look at http://pgfouine.projects.postgresql.org/

你可以看看 http://pgfouine.projects.postgresql.org/

回答by user3617786

pg_activityis what we use. https://github.com/dalibo/pg_activity

pg_activity是我们使用的。 https://github.com/dalibo/pg_activity

It's a great tool with a top-like interface

这是一个很棒的工具,具有类似top的界面