一、问题描述
因为工作需要,将BLOBS表空间内的数据迁移至新建表空间BLOBS1,迁移数据后在删除BLOBS表空间报错如下:
DROP TABLESPACE BLOBSOLD INCLUDING CONTENTS AND DATAFILES;
说明:BLOBS表空间存放的是LOB数据,LOB数据所属表在USERS表空间上。
二、原因分析
可能是因为BLOBS表空间中还有数据没有迁移完,倒是无法删除。
使用如下语句检查BLOBS表空间是否还有数据:
select owner, table_name, column_name, tablespace_name
from dba_lobs
where tablespace_name ='BLOBS
发现有结果输出,印证了之前的猜测。
三、处理方法
注意:操作前请做好必要备份,以免数据丢失。
继续迁移数据
1.使用如下脚本生成开启表行移动和关闭表行移动的批量执行语句
–生成开启表行移动的批量执行语句(批量语句1)
select 'alter table ' || owner || '.' || table_name || ' enable row movement ;'
from dba_lobs where tablespace_name = 'BLOBS';
–生成关闭表行移动的批量执行语句(批量语句2)
select 'alter table ' || owner || '.' || table_name || ' disable row movement ;'
from dba_lobs where tablespace_name = 'BLOBS';
2.使用如下脚本生成执行语句迁移数据
–生成将BLOBS表空间数据move到BLOBS1表空间的批量执行语句(批量语句3)
select 'alter table ' || owner || '.' || table_name || ' move lob(' ||
column_name || ') store as (tablespace BLOBS1);'
from dba_lobs
where tablespace_name = 'BLOBS' ;
或:
select 'alter table ' || xtable || ' move tablespace BLOBS lob(' ||
column_name || ') store as ( tablespace BLOBS1);'
from (select owner || '.' || table_name xtable,
column_name,
tablespace_name
from dba_lobs
where tablespace_name = 'BLOBS')
3.依次执行前面生成的批量执行语句
步骤1:执行批量语句1
步骤2:执行批量语句3
步骤3:执行批量语句2
4.尝试删除BLOBS表空间
上述命令执行完成后,再次尝试删除BLOBS表空间。
如果还是报错,有可能是因为存在约束,可通过如下命令生成执行命令:
select 'alter table ' || owner || '.' || table_name || ' drop constraint ' ||
constraint_name || ' ;'
from dba_constraints
where constraint_type in ('U', 'P')
and (index_owner, index_name) in
(select owner, segment_name
from dba_segments
where tablespace_name = 'BLOBS');
删除约束后,可再次尝试删除BLOBS表空间。
正常情况下,此时可成功删除表空间。
参考:
https://blog.51cto.com/u_4048786/3203618