Postgresql

Autovacuum 不清除數據庫

  • May 10, 2022

Autovacuum 不會清除數據庫。數據庫中間數據庫 Postgres 10.18,AWS RDS(vCPU 2,RAM 8Gb,SSD(gp2)1100Gib)

表“spree_datafeed_products”

relid               | 16556
schemaname          | public
relname             | spree_datafeed_products
seq_scan            | 20
seq_tup_read        | 365522436
idx_scan            | 962072108
idx_tup_fetch       | 9929276855
n_tup_ins           | 2846455
n_tup_upd           | 35778058
n_tup_del           | 284291955
n_tup_hot_upd       | 0
n_live_tup          | 3546840
n_dead_tup          | 338790851
n_mod_since_analyze | 307930753
last_vacuum         | 
last_autovacuum     | 
last_analyze        | 
last_autoanalyze    | 2022-04-29 13:01:43.985749+00
vacuum_count        | 0
autovacuum_count    | 0
analyze_count       | 0
autoanalyze_count   | 1

表和索引大小:

indexname                           | size  
index_spree_datafeed_products_on_updated_at                  | 48 GB
index_spree_datafeed_products_on_state                       | 35 GB
index_spree_datafeed_products_on_size_variant_field          | 40 GB
index_spree_datafeed_products_on_product_id                  | 32 GB
index_spree_datafeed_products_on_original_id                 | 31 GB
index_spree_datafeed_products_on_datafeed_id                 | 42 GB
index_spree_datafeed_products_on_datafeed_id_and_original_id | 31 GB
index_spree_datafeed_products_on_data_hash                   | 39 GB
spree_datafeed_products_pkey                                 | 18 GB

pg_size_pretty  - 419 GB

工人:

datid            | 16404
datname          | milanstyle_production
pid              | 2274
backend_start    | 2022-05-01 19:52:00.066097+00
xact_start       | 2022-05-01 19:52:00.23692+00
query_start      | 2022-05-01 19:52:00.23692+00
state_change     | 2022-05-01 19:52:00.236921+00
wait_event_type  | 
wait_event       | 
state            | active
backend_xid      | 
backend_xmin     | 1301636863
query            | autovacuum: VACUUM ANALYZE public.spree_datafeed_products
backend_type     | autovacuum worker

設置:

autovacuum on
autovacuum_analyze_scale_factor 0.05
autovacuum_analyze_threshold 50
autovacuum_freeze_max_age 200000000
autovacuum_max_workers 3
autovacuum_multixact_freeze_max_age 400000000
autovacuum_naptime 30
autovacuum_vacuum_cost_delay 20
autovacuum_vacuum_cost_limit -1
autovacuum_vacuum_scale_factor 0.1
autovacuum_vacuum_threshold 50

垃圾清理腳本積累了大量的刪除條目。我們已經等待了一個多星期(自動清關)。問題是什麼?為什麼數據庫失敗?

使用這些設置清理該大小的表將需要很長時間(假設您未顯示的設置為預設值)。

如果活元組真的是死元組的 1%,那麼擺脫這個漏洞的最簡單方法可能是表的 VACUUM FULL。

為了避免再次回到那個洞,您至少應該將 autovacuum_vacuum_cost_delay 降低到 2 並將 autovacuum_work_mem 增加到至少 256MB(但我可能會做 1GB)。

我還會查看日誌,看看 autovacs 是否有在完成之前被取消的歷史。

引用自:https://dba.stackexchange.com/questions/311931