小编pat*_*ick的帖子

你如何防止死行在 postgresql 中徘徊?

我在亚马逊上有生产和暂存 RDS 实例,暂存数据是生产的直接副本,因此两个实例都有重复的数据。

做一个EXPLAIN ANALYZE SELECT * from my_table WHERE my_col=true;结果是:

Seq Scan on my_table (cost=0.00..142,775.73 rows=1 width=1,436) (actual time=18,170.294..18,170.294 rows=0 loops=1) Filter: my_col Rows Removed by Filter: 360275
Run Code Online (Sandbox Code Playgroud)

在生产中,它是:

Seq Scan on my_table (cost=0.00..62,145.88 rows=1 width=1,450) (actual time=282.487..282.487 rows=0 loops=1) Filter: my_col Rows Removed by Filter: 366442
Run Code Online (Sandbox Code Playgroud)

跑步时 select pg_total_relation_size('my_table'::regclass);

我发现舞台的大小几乎是制作的两倍。从我读过的内容来看,我看到 postgresql 的 MVCC 对此负责,因为它保留了多个版本的行。我手动运行VACUUM FULL,然后看到 staging 的大小已经减少了 2/3。现在运行相同的解释分析显示:

Seq Scan on my_table  (cost=0.00..56094.75 rows=1 width=1436) (actual time=1987.340..1987.340 rows=0 loops=1) Filter: my_col Rows Removed by …
Run Code Online (Sandbox Code Playgroud)

postgresql

7
推荐指数
1
解决办法
7051
查看次数

标签 统计

postgresql ×1