DB2_收缩表空间

本文详细介绍了如何在DB2数据库中进行表空间的收缩操作,包括自动存储管理和数据库管理两种方式,旨在回收未使用的空间。通过创建、填充、删除表以及使用REDUCE命令,展示了收缩过程及注意事项,帮助理解DB2表空间管理。
摘要由CSDN通过智能技术生成

目的:
测试DB2收缩表空间,本脚本摘录自DB2安装目录admin_scripts/tbsreduce.db2。
版本:Windows DB2 Express-C V9.7

操作步骤:
使用"db2cmd db2 -t"进入交互模式,执行后续操作。
-- Set auto-commit of SQL statements to OFF.
UPDATE COMMAND OPTIONS USING c OFF;

-- Create database.
!db2start;
CREATE DB testdb1;

-- Connect to database.
CONNECT TO testdb1;

1,自动存储管理表空间未使用空间回收:
-- Create table space 'tbsp_auto' managed by AUTOMATIC STORAGE.
CREATE TABLESPACE tbsp_auto PAGESIZE 4096 MANAGED BY AUTOMATIC STORAGE
  EXTENTSIZE 2 AUTORESIZE NO INITIALSIZE 107K;

-- Create table 'tab_auto1' in table space 'tbsp_auto'.
CREATE TABLE tab_auto1 ( c1 char( 250 ),c2 char( 250 ),c3 char( 250 ),
                         c4 char( 250 ),c5 char( 250 ),c6 char( 250 ),
                         c7 char( 250 ),c8 char( 250 ),c9 char( 250 ),
                         c10 char( 250 ) )
  IN tbsp_auto;

-- Populate table 'tab_auto1' with the following data.
INSERT INTO tab_auto1 VALUES ('a', 'b', 'c', 'd', 'e',
                              'f', 'g', 'h', 'i', 'j' );

-- Create table 'tab_auto2' in table space 'tbsp_auto'.
CREATE TABLE tab_auto2 ( c1 char( 250 ),c2 char( 250 ),c3 char( 250 ),
                         c4 char( 250 ),c5 char( 250 ),c6 char( 250 ),
                         c7 char( 250 ),c8 char( 250 ),c9 char( 250 ),
                         c10 char( 250 ) )
  IN tbsp_auto;

-- Populate table 'tab_auto2' with data so that the table space is full.
-------------------------------------------------------------------------------
-- Table space 'tbsp_auto' will be full after the five INSERT statements shown
-- below. Creation of new tables in table space 'tbsp_auto' will fail with an
-- error: "Unable to allocate new pages in table space".
-------------------------------------------------------------------------------
INSERT INTO tab_auto2 VALUES ('a', 'b', 'c', 'd', 'e',
                              'f', 'g', 'h', 'i', 'j' );
INSERT INTO tab_auto2 (SELECT * FROM tab_auto2);
INSERT INTO tab_auto2 (SELECT * FROM tab_auto2);
INSERT INTO tab_auto2 (SELECT * FROM tab_auto1);
INSERT INTO tab_auto2 (SELECT * FROM tab_auto2);

-- Create table 'tab_auto3' in table space 'tbsp_auto'. Table creation
-- will fail with the following error:
-- "Unable to allocate new pages in table space".
CREATE TABLE tab_auto3 ( c1 char( 250 ),c2 char( 250 ),c3 char( 250 ),
                         c4 char( 250 ),c5 char( 250 ),c6 char( 250 ),
                         c7 char( 250 ),c8 char( 250 ),c9 char( 250 ),
                         c10 char( 250 ) )
  IN tbsp_auto;

! echo "Above error is expected !";

-- Take a snapshot of the table space. This will give details such as:
-- table space name, high water mark, extent size, used pages, free pages,
-- pending free pages for table space 'tbsp_auto'.
SELECT SUBSTR (tablespace_name, 1, 10) AS TABLESPACE_NAME,
       high_water_mark, extent_size, used_pages,
       free_pages, pending_free_pages
  FROM TABLE (snapshot_tbs_cfg ('testdb1', -1)) AS snapshot_tbs_cfg
  WHERE tablespace_name='TBSP_AUTO';
--TABLESPACE_NAME HIGH_WATER_MARK   EXTENT_SIZE   USED_PAGES    FREE_PAGES    PENDING_FREE_PAGES
----------------- ----------------- ------------- ------------- ------------- --------------------
--TBSP_AUTO                      24             2            22             0                    2


-- Dr

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值