如何判断 PostgreSQL 的 Autovacuum 是否在 UNIX 上运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19826467/
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 can I tell if PostgreSQL's Autovacuum is running on UNIX?
提问by Clint Pachl
How can one tell if the autovacuum daemonin Postgres 9.x is running and maintaining the database cluster?
如何判断Postgres 9.x 中的autovacuum 守护进程是否正在运行和维护数据库集群?
回答by Clint Pachl
PostgreSQL 9.3
PostgreSQL 9.3
Determine if Autovacuum is Running
确定 Autovacuum 是否正在运行
This is specific to Postgres 9.3 on UNIX. For Windows, see this question.
这特定于 UNIX 上的 Postgres 9.3。对于 Windows,请参阅此问题。
Query Postgres System Table
查询 Postgres 系统表
SELECT
schemaname, relname,
last_vacuum, last_autovacuum,
vacuum_count, autovacuum_count -- not available on 9.0 and earlier
FROM pg_stat_user_tables;
Grep System Process Status
Grep 系统进程状态
$ ps -axww | grep autovacuum
24352 ?? Ss 1:05.33 postgres: autovacuum launcher process (postgres)
Grep Postgres Log
Grep Postgres 日志
# grep autovacuum /var/log/postgresql
LOG: autovacuum launcher started
LOG: autovacuum launcher shutting down
If you want to know more about the autovacuumactivity, set log_min_messages
to DEBUG1..DEBUG5
. The SQL command VACUUM VERBOSE
will output information at log level INFO
.
如果您想了解有关autovacuum活动的更多信息,请设置log_min_messages
为DEBUG1..DEBUG5
。SQL 命令VACUUM VERBOSE
将在日志级别输出信息INFO
。
Regarding the Autovacuum Daemon, the Posgres docs state:
关于 Autovacuum Daemon,Posgres 文档指出:
In the default configuration, autovacuuming is enabled and the related configuration parameters are appropriately set.
在默认配置中,启用了自动清理并适当设置了相关的配置参数。
See Also:
也可以看看:
回答by Charly Koza
I'm using:
我正在使用:
select count(*) from pg_stat_activity where query like 'autovacuum:%';
in collectd to know how many autovacuum are running concurrently.
在 collectd 中了解有多少 autovacuum 同时运行。
You may need to create a security function like this:
您可能需要创建这样的安全功能:
CREATE OR REPLACE FUNCTION public.pg_autovacuum_count() RETURNS bigint
AS 'select count(*) from pg_stat_activity where query like ''autovacuum:%'';'
LANGUAGE SQL
STABLE
SECURITY DEFINER;
and call that from collectd.
并从 collectd 调用它。
In earlier Postgres, "query" was "current_query" so change it according to what works.
在较早的 Postgres 中,“query”是“current_query”,因此请根据有效的方式更改它。
回答by Philip Snyder
You can also run pg_activity to see the currently running queries on your database. I generally leave a terminal open with this running most of the time anyway as it's veryuseful.
您还可以运行 pg_activity 来查看当前正在数据库上运行的查询。无论如何,我通常会在大多数时间运行终端时打开终端,因为它非常有用。