1
我有一張很大的桌子。所以我劃分了這張桌子。並將主表中的所有記錄複製到子表中。然後我刪除了主表中的所有記錄。現在我的主表是空的。對子表進行查詢的速度非常快。但是在主表上執行查詢仍然很慢。它出什麼問題了?爲什麼在主表上查詢非常慢?
postgres=# select count(*) from only cdr;
count
-------
0
(1 row)
postgres=# explain select count(*) from only cdr;
QUERY PLAN
-----------------------------------------------------------------------
Aggregate (cost=2045094.31..2045094.32 rows=1 width=0)
-> Seq Scan on cdr (cost=0.00..2044867.85 rows=90585 width=0)
(2 rows)
postgres=# EXPLAIN ANALYZE select count(*) from only cdr;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
-----
Aggregate (cost=2045094.31..2045094.32 rows=1 width=0) (actual time=168385.356..168385.356 rows=1 loops=1)
-> Seq Scan on cdr (cost=0.00..2044867.85 rows=90585 width=0) (actual time=168385.351..168385.351 rows=0 loop
s=1)
Total runtime: 168385.404 ms
(3 rows)
我也在主表上運行真空分析。但仍然沒有運氣。
postgres =#vacuum analyze cdr; 真空
我發現一些其他人也有同樣的問題。也許根本原因是,雖然master表中的舊記錄已被刪除,但psql仍以某種方式掃描這些垃圾數據。一種解決方案是創建一個新的主表,並放棄舊的主表。但是這個解決方案並不適合我。任何其他解決方案沒有停機?謝謝!
您是否在主控上運行過「真空分析」? –
我已經運行「真空分析cdr;」。但現在它仍然很慢。 –