Tablespace表空間刪除
一、普通表空間刪除:
Oracle 11g刪除表空間語法描述:
DROP TABLESPACE tablespace_name [ including contents [ and datafiles ] [ CASCADE CONSTRAINT 搜尋] ];
無選項 -- 當表空間為空才能刪除;
including contents — 刪除表空間及物件;
including contents and datafiles — 刪除表空間、物件及資料檔案;
including contents CASCADE CONSTRAINT — 刪除關聯;
including contents and datafiles cascade constraint -- 含前兩項。
生成指令碼:
select 'drop tablespace '||tablespace_name||' including contents and datafiles cascade constraint;' from dba_data_files where tablespace_name not in('SYSTEM','SYSAUX','USERS','EXAMPLE','UNDOTBS2','UNDOTBS1')
二、分割槽表空間刪除:
select 'alter table '||owner||'.'||segment_name||' drop partition '||partition_name||' ;'
from dba_segments
where segment_name in (select distinct segment_name
from dba_segments
where tablespace_name = 'p1'
and segment_type like '%PART%')
and tablespace_name <> 'p1';
得出:
alter table CP.IDX_CP_HANDLE_BATCH_NO drop partition SYS_P200 ;
alter table CP.IDX_CP_HANDLE_REQUEST_ID drop partition SYS_P200 ;
alter table CP.IDX_CP_PAYMENT_REQUEST_ID drop partition SYS_P201 ;
alter table CP.IDX_CP_PAYMENT_TRAN_NO drop partition SYS_P201 ;
alter table CP.IDX_CP_REQUEST_ID drop partition SYS_P199 ;
alter table CP.IDX_CP_REQUEST_TRAN_NO drop partition SYS_P199 ;
alter table CP.TBL_CP_HANDLE drop partition SYS_P200 ;
alter table CP.TBL_CP_PAYMENT drop partition SYS_P201 ;
alter table CP.TBL_CP_REQUEST drop partition SYS_P199 ;
三、異常處理:
報錯有下面幾種:
一. ORA-23515
--- ORA-23515: materialized views and/or their indices exist in the tablespace
drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-23515: materialized views and/or their indices exist in the tablespace
意思是:該表空間 CRM_DATA含有物化檢視,或者含有物化檢視的索引
解決辦法:
-- 首先刪掉該表空間下的的物化檢視
select 'drop materialized view '||owner||'.'||segment_name||' ;'
from dba_segments
where segment_name in (select mview_name from dba_mviews)
and tablespace_name = 'CRM_DATA'
-- 然後刪除該表空間下的其他表空間下物化檢視在本表空間下建立的索引
select *
from dba_segments
where tablespace_name = 'CRM_DATA'
and segment_name in
(select index_name
from dba_indexes
where table_name in (select mview_name from dba_mviews));
二. ORA-02429
---ORA-02429: cannot drop index used for enforcement of unique/primary key
drop tablespace crm_idx including contents cascade constraints
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-02429: cannot drop index used for enforcement of unique/primary key
ORA-02429的意思是: 讓你刪除該表空間下面的 primary key 和 unique key
處理辦法:
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 = 'CRM_IDX');
三. ORA-14404
--ORA-14404: partitioned table contains partitions in a different tablespace
drop tablespace crm_arc_data including contents and datafiles
*
ERROR at line 1:
ORA-14404: partitioned table contains partitions in a different tablespace
意思是: 本表空間下面有這麼樣一個或一些分割槽表的分割槽: this partition OR partitions的table所包含的全部 partitions不在一個表空間下面:
處理辦法:
select 'alter table '||owner||'.'||segment_name||' drop partition '||partition_name||' ;'
from dba_segments
where segment_name in (select distinct segment_name
from dba_segments
where tablespace_name = 'CRM_ARC_DATA'
and segment_type like '%PART%')
and tablespace_name <> 'CRM_ARC_DATA';
殺手鐧: 直接drop 這個分割槽表(如果允許的話)
四. ORA-02449
--- ORA-02449: unique/primary keys in table referenced by foreign keys
drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
意思是: 這個要刪除的表空間 裡面含有這麼樣的一些主鍵: 其他表空間的表在這些主鍵上建有外來鍵
處理辦法: 去掉這些垃圾外來鍵
select 'alter table '||owner||'.'||table_name||' drop constraint '||constraint_name||' ;'
from dba_constraints
where constraint_type = 'R'
and table_name in (select segment_name
from dba_segments
where tablespace_name = 'CRM_DATA'
and segment_type like '%TABLE%');
如果還是不行的話,就用這個語句來刪表空間吧:
drop tablespace crm_data including contents cascade constraints
Oracle 11g刪除表空間語法描述:
DROP TABLESPACE tablespace_name [ including contents [ and datafiles ] [ CASCADE CONSTRAINT 搜尋] ];
無選項 -- 當表空間為空才能刪除;
including contents — 刪除表空間及物件;
including contents and datafiles — 刪除表空間、物件及資料檔案;
including contents CASCADE CONSTRAINT — 刪除關聯;
including contents and datafiles cascade constraint -- 含前兩項。
生成指令碼:
select 'drop tablespace '||tablespace_name||' including contents and datafiles cascade constraint;' from dba_data_files where tablespace_name not in('SYSTEM','SYSAUX','USERS','EXAMPLE','UNDOTBS2','UNDOTBS1')
二、分割槽表空間刪除:
select 'alter table '||owner||'.'||segment_name||' drop partition '||partition_name||' ;'
from dba_segments
where segment_name in (select distinct segment_name
from dba_segments
where tablespace_name = 'p1'
and segment_type like '%PART%')
and tablespace_name <> 'p1';
得出:
alter table CP.IDX_CP_HANDLE_BATCH_NO drop partition SYS_P200 ;
alter table CP.IDX_CP_HANDLE_REQUEST_ID drop partition SYS_P200 ;
alter table CP.IDX_CP_PAYMENT_REQUEST_ID drop partition SYS_P201 ;
alter table CP.IDX_CP_PAYMENT_TRAN_NO drop partition SYS_P201 ;
alter table CP.IDX_CP_REQUEST_ID drop partition SYS_P199 ;
alter table CP.IDX_CP_REQUEST_TRAN_NO drop partition SYS_P199 ;
alter table CP.TBL_CP_HANDLE drop partition SYS_P200 ;
alter table CP.TBL_CP_PAYMENT drop partition SYS_P201 ;
alter table CP.TBL_CP_REQUEST drop partition SYS_P199 ;
三、異常處理:
報錯有下面幾種:
一. ORA-23515
--- ORA-23515: materialized views and/or their indices exist in the tablespace
drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-23515: materialized views and/or their indices exist in the tablespace
意思是:該表空間 CRM_DATA含有物化檢視,或者含有物化檢視的索引
解決辦法:
-- 首先刪掉該表空間下的的物化檢視
select 'drop materialized view '||owner||'.'||segment_name||' ;'
from dba_segments
where segment_name in (select mview_name from dba_mviews)
and tablespace_name = 'CRM_DATA'
-- 然後刪除該表空間下的其他表空間下物化檢視在本表空間下建立的索引
select *
from dba_segments
where tablespace_name = 'CRM_DATA'
and segment_name in
(select index_name
from dba_indexes
where table_name in (select mview_name from dba_mviews));
二. ORA-02429
---ORA-02429: cannot drop index used for enforcement of unique/primary key
drop tablespace crm_idx including contents cascade constraints
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-02429: cannot drop index used for enforcement of unique/primary key
ORA-02429的意思是: 讓你刪除該表空間下面的 primary key 和 unique key
處理辦法:
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 = 'CRM_IDX');
三. ORA-14404
--ORA-14404: partitioned table contains partitions in a different tablespace
drop tablespace crm_arc_data including contents and datafiles
*
ERROR at line 1:
ORA-14404: partitioned table contains partitions in a different tablespace
意思是: 本表空間下面有這麼樣一個或一些分割槽表的分割槽: this partition OR partitions的table所包含的全部 partitions不在一個表空間下面:
處理辦法:
select 'alter table '||owner||'.'||segment_name||' drop partition '||partition_name||' ;'
from dba_segments
where segment_name in (select distinct segment_name
from dba_segments
where tablespace_name = 'CRM_ARC_DATA'
and segment_type like '%PART%')
and tablespace_name <> 'CRM_ARC_DATA';
殺手鐧: 直接drop 這個分割槽表(如果允許的話)
四. ORA-02449
--- ORA-02449: unique/primary keys in table referenced by foreign keys
drop tablespace crm_data including contents and datafiles
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by foreign keys
意思是: 這個要刪除的表空間 裡面含有這麼樣的一些主鍵: 其他表空間的表在這些主鍵上建有外來鍵
處理辦法: 去掉這些垃圾外來鍵
select 'alter table '||owner||'.'||table_name||' drop constraint '||constraint_name||' ;'
from dba_constraints
where constraint_type = 'R'
and table_name in (select segment_name
from dba_segments
where tablespace_name = 'CRM_DATA'
and segment_type like '%TABLE%');
如果還是不行的話,就用這個語句來刪表空間吧:
drop tablespace crm_data including contents cascade constraints
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21374452/viewspace-2155295/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【TABLESPACE】Oracle表空間最佳實踐Oracle
- 刪除臨時表空間組
- oracle級聯刪除使用者,刪除表空間Oracle
- 【TABLESPACE】Oracle 表空間結構說明Oracle
- oracle建立臨時表空間和資料表空間以及刪除Oracle
- 刪除表空間時,遇到了ORA-14404錯誤
- 刪除表空間出現ORA-22868錯誤(一)
- 刪除UNDO表空間並處理ORA-01548問題
- MySQL 5.7的表刪除資料後的磁碟空間釋放MySql
- Linux檔案刪除空間未釋放Linux
- RM刪除檔案空間釋放詳解
- Oracle 刪除使用者、表空間、資料檔案、使用者下的所有表Oracle
- 16、表空間 建立表空間
- ORA-1653: unable to extend table by 1024 in tablespace(oracle表空間滿了的解決方案)Oracle
- [待整理]oracle10g刪除(釋放)資料檔案/表空間流程Oracle
- 如何刪除 Mac 儲存空間的其他選項?Mac
- oracle 臨時表空間的增刪改查Oracle
- Oracle11g新增檢視查詢表空間使用率DBA_TABLESPACE_USAGE_METRICSOracle
- laravel 多對多關聯刪除中間表Laravel
- 修改刪除表
- Linux檔案刪除但空間不釋放問題篇Linux
- Mysql InnoDB刪除資料後釋放磁碟空間的方法MySql
- 刪使用者刪表空間的操作還能flashback回來嗎?
- oracle 表空間Oracle
- PostgreSQL 表空間SQL
- Oracle表空間Oracle
- PostgreSQL:表空間SQL
- 當使用者無限制使用表空間配額且表空間有足夠空間時出現超出表空間的空間限額
- 表空間利用率及表空間的補充
- PbootCMS快取runtime能刪除嗎?空間滿了怎麼辦?boot快取
- Mac蘋果儲存空間的其他選項該如何刪除?Mac蘋果
- UNDO表空間空間回收及切換
- C練習--刪除每個輸入行末尾空格及製表符,並刪除完全是空的行
- 【Oracle】表空間誤刪除導致startup啟動時提示ORA-01110和ORA-01157錯誤Oracle
- 處理Linux刪除檔案後空間未釋放的問題Linux
- win10 硬碟空間無法刪除應該怎麼解決Win10硬碟
- (轉載)刪除檔案後硬碟空間不釋放的問題硬碟
- KingbaseES的表空間