在Postgres DB中查找增加UPDATES的表源

时间:2017-03-16 20:39:44

标签: postgresql

我监控的Postgres数据库之一正在被大量的UPDATES所淹没。什么是Postgres中最好的方法来轻松识别我的实例中的哪些表正在获取大量这些DML请求?

1 个答案:

答案 0 :(得分:2)

您可以使用pg_stat_all_tables,例如:

t=# create table t19 (i int);
CREATE TABLE
t=# insert into t19 select 1;
INSERT 0 1
t=# select schemaname,relname,n_tup_upd from pg_stat_all_tables order by n_tup_upd desc limit 2;
 schemaname |     relname     | n_tup_upd
------------+-----------------+-----------
 pg_catalog | pg_operator     |         0
 pg_catalog | pg_auth_members |         0
(2 rows)

t=# update t19 set i=2;
UPDATE 1
t=# update t19 set i=2;
UPDATE 1
t=# select schemaname,relname,n_tup_upd from pg_stat_all_tables order by n_tup_upd desc limit 2;
 schemaname |   relname   | n_tup_upd
------------+-------------+-----------
 public     | t19         |         2
 pg_catalog | pg_operator |         0
(2 rows)