在db2中删除分区后,我试图编写一个存储的proc来回收磁盘空间。
CREATE OR REPLACE PROCEDURE RECLAIM_PARTITION_SPACE(OUT RESPONSE_MESS
VARCHAR(200))
LANGUAGE SQL
BEGIN
DECLARE REDUCE_STOP VARCHAR(200);
DECLARE LOWER_HIGH_WATER_MARK VARCHAR(200);
DECLARE REDUCE_MAX VARCHAR(200);
DECLARE V_MSG VARCHAR(80);
DECLARE V_OUTSTATUS INTEGER DEFAULT 0;
DECLARE V_SECONDS INTEGER DEFAULT 300;
SET REDUCE_STOP = 'ALTER TABLESPACE TS_PART_TABLES REDUCE STOP';
SET LOWER_HIGH_WATER_MARK = 'ALTER TABLESPACE TS_PART_TABLES LOWER HIGH WATER MARK';
SET REDUCE_MAX = 'ALTER TABLESPACE TS_PART_TABLES REDUCE MAX';
BEGIN
EXECUTE IMMEDIATE REDUCE_STOP;
EXECUTE IMMEDIATE LOWER_HIGH_WATER_MARK;
END;
CALL DBMS_ALERT.WAITONE('wait for reduce max' , V_MSG , V_OUTSTATUS , V_SECONDS);
BEGIN
EXECUTE IMMEDIATE REDUCE_STOP;
EXECUTE IMMEDIATE REDUCE_MAX;
END;
COMMIT WORK;
END@
GRANT EXECUTE ON PROCEDURE RECLAIM_PARTITION_SPACE(VARCHAR(200)) TO
USER DB2INST1@
但是,当我运行此存储的proc时,没有回收,但是,当我手动运行查询ALTER TABLESPACE TS_PART_TABLES LOWER HIGH WATER MARK后跟ALTER TABLESPACE TS_PART_TABLES REDUCE MAX时,将为已删除的分区回收磁盘空间。
在存储过程中我怎么了?
答案 0 :(得分:0)
在立即执行LOWER_HIGH_WATER_MARK和立即执行REDUCE_MAX之后添加提交解决了该问题。 这是因为在使用EXECUTE IMMEDIATE时,使用DDL语句而不是DML语句执行隐式提交。 (来源:https://searchoracle.techtarget.com/answer/Telling-EXECUTE-IMMEDIATE-to-commit)