DB2 列式存儲表的空間回收

如果一張表是列式存儲的,比如:

CREATE TABLE "DB2TST  "."T0417"  (
                  "ID" INTEGER )   
                 IN "TBS2" 
                 ORGANIZE BY COLUMN;
                 
那麼刪除完數據之後的騰出來的空間是無法被新插入的數據使用的,表只會越來越大。並且無法按照普通表的方式去reorg表,會報錯SQL1667N:

db2 reorg table t0417
SQL1667N  The operation failed because the operation is not supported with the
type of the specified table.  Specified table: "T0417".  Table type: "ORGANIZE
BY COLUMN".  Operation: "REORG TABLE".  SQLSTATE=42858

信息中心的頁面 Space reclamation for column-organized tables 中有明確說明,列式存儲的表刪除數據以後的空間不能被複用

When a row in a column-organized table is deleted, the row is logically (but not physically) deleted. As a result, the space that is used by the deleted row is not available to subsequent transactions, and remains unusable until space reclamation occurs. For example, consider the case where a table is created and 1 million rows are inserted in batch operation A. The size of the table on disk after batch operation A is 5 MB. After some time, batch operation B inserts another 1 million rows. Now the table consumes 10 MB on disk. At this point, all of the rows that were inserted in batch operation A are deleted, and the table size on disk remains 10 MB. If a third batch operation C inserts another 1 million rows into the table, 5 MB of additional space is required. (With row-organized tables, the rows that are inserted in batch operation C would use the space that was vacated by the deleted rows from batch operation A.) A REORG TABLE command is required to reclaim the space that was used by the rows inserted in batch operation A.

因此,刪除完數據之後,要想回收空間,必須做reorg操作,而且要帶有RECLAIM EXTENTS參數:

db2 reorg table tablename RECLAIM EXTENTS ALLOW WRITE ACCESS

https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.admin.perf.doc/doc/c0061069.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章