1. 程式人生 > >手動執行VACUUM,無法清理表中的dead tuple

手動執行VACUUM,無法清理表中的dead tuple

目錄

環境

症狀

問題原因

解決方案

環境

系統平臺:N/A

版本:4.1.1

症狀

  應用方反映業務量不大的情況下伺服器負載較高,執行SQL的速度明顯感覺緩慢。檢查資料庫TOP SQL,發現與表test有關,檢視該表的統計值,live_tuple只有91966條,dead tuple為702346條。

  

highgo=# select n_live_tup,n_dead_tup from pg_stat_all_tables where relname = 'test';

 n_live_tup | n_dead_tup

------------+------------

    91966 |   702346

(1 row)

  手動對該表執行VACUUM同樣無法回收dead tuple,報錯如下:

 

highgo=# vacuum(verbose,analyze) test;

INFO:  00000: vacuuming "public.test"

INFO:  00000: index "index_test_content_id" now contains 146076 row versions in 698 pages

DETAIL:  0 index row versions were removed.

175 index pages have been deleted, 126 are currently reusable.

CPU 0.00s/0.00u sec elapsed 0.00 sec.

INFO:  00000: index "test_pkey" now contains 146076 row versions in 568 pages

DETAIL:  0 index row versions were removed.

77 index pages have been deleted, 68 are currently reusable.

CPU 0.00s/0.00u sec elapsed 0.00 sec.

INFO:  00000: "test": found 0 removable, 789485 nonremovable row versions in 10178 out of 10276 pages

DETAIL:  702346 dead row versions cannot be removed yet.

There were 59707 unused item pointers.

Skipped 0 pages due to buffer pins.

0 pages are entirely empty.

CPU 0.04s/0.15u sec elapsed 0.20 sec.

INFO:  00000: vacuuming "pg_toast.pg_toast_16737"

INFO:  00000: index "pg_toast_16737_index" now contains 0 row versions in 1 pages

DETAIL:  0 index row versions were removed.

0 index pages have been deleted, 0 are currently reusable.

CPU 0.00s/0.00u sec elapsed 0.13 sec.

INFO:  00000: "pg_toast_16737": found 0 removable, 0 nonremovable row versions in 0 out of 0 pages

DETAIL:  0 dead row versions cannot be removed yet.

There were 0 unused item pointers.

Skipped 0 pages due to buffer pins.

0 pages are entirely empty.

CPU 0.00s/0.00u sec elapsed 0.59 sec.

INFO:  00000: analyzing "public.test"

INFO:  00000: "test": scanned 10276 of 10276 pages, containing 90959 live rows and 702346 dead rows; 30000 rows in sample, 90959 estimated total row

 

問題原因

 當我們開啟一個事務後,為了實現多版本的控制,資料庫會阻止未結束的長事務之後產生的所有dead tuple,即使與該事務無關的其他表也是如此。

 

- Live transactions performing a write operation in any table will prevent vacuuming dead rows

generated by commited transactions that started after first live transaction in any other table.

詳細的解決方案請登入【瀚高技術支援平臺】檢視

https://support.highgo.com/#/index/docContent/35b88a720452d610