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

猜你喜欢

转载自blog.csdn.net/qingsong3333/article/details/105584624