广告
返回顶部
首页 > 资讯 > 数据库 >Tablespace表空间删除
  • 554
分享到

Tablespace表空间删除

2024-04-02 19:04:59 554人浏览 独家记忆
摘要

一、普通表空间删除: oracle 11g删除表空间语法描述: DROP TABLESPACE tablespace_name   [ including contents [ and d

一、普通表空间删除:
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


您可能感兴趣的文档:

--结束END--

本文标题: Tablespace表空间删除

本文链接: https://www.lsjlt.com/news/47340.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Tablespace表空间删除
    一、普通表空间删除: Oracle 11g删除表空间语法描述: DROP TABLESPACE tablespace_name   [ including contents [ and d...
    99+
    2022-10-18
  • oracle删除表空间
    表空间离线SQL> alter tablespace  rcat offile;2.删除用户    SQL>drop user ractowne...
    99+
    2022-10-18
  • shell脚本操作oracle删除表空间、创建表空间、删除用户
    oracle下表空间的导出,用户的删除,表空间删除,用户新建,表空间新建,数据导入的shell使用非oracle用户执行该脚本参数说名$1:base表空间的用户名$2:同步表空间的用户名使用场景测试用,ba...
    99+
    2022-06-04
    空间 脚本 操作
  • oracle 删除表空间与用户
    以system用户登录,查找需要删除的用户: --查找用户 select  * from dba_users; --查找工作空间的路径select * from dba_data_files;    --删除用...
    99+
    2021-06-06
    oracle 删除表空间与用户
  • 如何编写shell脚本操作oracle删除表空间、创建表空间、删除用户
    本篇内容介绍了“如何编写shell脚本操作oracle删除表空间、创建表空间、删除用户”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!orac...
    99+
    2023-06-09
  • Oracle 表空间管理(tablespace managment)
    <span style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;ba...
    99+
    2022-10-18
  • oracle怎么删除表空间文件
    在Oracle中,要删除表空间文件,可以按照以下步骤进行操作:1. 首先,确认要删除的表空间文件不再被数据库使用。可以使用以下语句查...
    99+
    2023-08-18
    oracle
  • oracle怎么删除用户和表空间
    要删除Oracle用户和表空间,可以按照以下步骤进行操作:1. 登录到Oracle数据库的管理员账号(如sys用户)。2. 确保当前...
    99+
    2023-08-23
    oracle
  • Tbs_P1:创建、更改和删除表空间
    SQL>conn system/oracle SQL>CREATE TABLESPACE  tbs_peenboo DATAFILE'/oradata/t...
    99+
    2022-10-18
  • oracle 删除用户后释放表空间
    有个用户占用大量存储。删除之后表空间没有释放。。。。 网上百度一番后: 先使用语句查询表空间大小 HWM。HWM说明参考:https://www.cnblogs.com/husam/p/6604437.html select...
    99+
    2019-10-09
    oracle 删除用户后释放表空间
  • oracle删除表空间报错怎么解决
    当Oracle删除表空间时报错,可能有以下几种情况: 表空间中包含对象或数据文件正在被使用:在删除表空间之前,需要确保表空间中不...
    99+
    2023-10-24
    oracle
  • Oracle 误删除表空间-恢复方式(一)
    针对Oracle 11.2.0.4 单实例版本测试演示过程:误操作删除表空间。前提是 没有重启库。[oracle@oracle fd]$ sqlplus / as sysdbaSQL*Plus: Relea...
    99+
    2022-10-18
  • Oracle中怎么删除用户和表空间
    Oracle中怎么删除用户和表空间,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Oracle 删除用户和表空间Oracle 使...
    99+
    2022-10-18
  • oracle10g如何删除数据文件/表空间
    小编给大家分享一下oracle10g如何删除数据文件/表空间,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧! ...
    99+
    2022-10-18
  • plsql怎么删除表空间的dbf文件
    你可以使用ALTER TABLESPACE语句来删除表空间的dbf文件。 步骤如下: 首先,使用以下语句查询要删除的表空间的db...
    99+
    2023-10-24
    plsql
  • oracle删除数据后怎么释放表空间
    在Oracle数据库中,使用DELETE语句删除数据只会删除数据行,而不会释放表空间。如果需要释放表空间,可以使用以下方法: 使...
    99+
    2023-10-26
    oracle
  • oracle中删除表空间提示ORA-00604和ORA-38301
       今天需要在本机上腾出空间,发现oracle中有一个dbf文件占了约30G,这个数据文件对应的用户平时很少使用的,于是就想对它进行处理-删除表空间操作。   本机...
    99+
    2022-10-18
  • oracle 用户、表空间的建立、删除和扩充
    create user mcc identified by manager; 这里注意密码不要用单引号扩起来。drop  user  mcc  cascade ;直接...
    99+
    2022-10-18
  • 【TABLESPACE】怎么使用resize使表空间变小
    问题:怎么使用resize使表空间变小  或者说怎么让表空间resize到一个合理的值,并且腾出部分空间 查看当前块(标准块)大小 点击(此处)折叠或打开 ...
    99+
    2022-10-18
  • eclipse如何删除工作空间
    要删除Eclipse工作空间,您可以按照以下步骤操作:1. 关闭Eclipse。2. 打开工作空间所在的文件夹。3. 在文件夹中找到...
    99+
    2023-09-21
    eclipse
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作