精华内容
下载资源
问答
  • oracle删除表空间数据
    千次阅读
    2021-06-02 16:17:11

    oracle删除表空间,一般是将表空间及其对应的数据文件一并删除,有时为了避免误删数据,可以先将表空间删除,数据文件保留一段时间,确认无误在进行删除。
    1、删除非空表空间,包含物理文件
    drop tablespace tablespace_name including contents and datafiles;
    如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS
    drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

    2、删除非空表空间,不包含物理文件
    drop tablespace tablespace_name including contents;

    3、删除空的表空间,不包含物理文件
    drop tablespace tablespace_name;

    4、删除空表空间,包含物理文件
    drop tablespace tablespace_name including datafiles;

    注:表空间的删除属于风险性操作,请谨慎操作。

    更多相关内容
  • -删除空的表空间,但是不包含物理文件drop tablespace tablespace_name;--删除非空表空间,但是不包含物理文件drop tablespace tablespace_name including contents;--删除表空间,包含物理文件drop tablespace ...

    -删除空的表空间,但是不包含物理文件

    drop tablespace tablespace_name;

    --删除非空表空间,但是不包含物理文件

    drop tablespace tablespace_name including contents;

    --删除空表空间,包含物理文件

    drop tablespace tablespace_name including datafiles;

    --删除非空表空间,包含物理文件

    drop tablespace tablespace_name including contents and datafiles;

    --如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS

    drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;

    以system用户登录,查找需要删除的用户:

    --查找用户

    select * from dba_users;

    --查找工作空间的路径

    select * from dba_data_files;

    --删除用户

    drop user 用户名称 cascade;

    --删除表空间

    drop tablespace 表空间名称 including contents and datafiles cascade constraint;

    例如:删除用户名成为ABC,表空间名称为ABC

    --删除用户,及级联关系也删除掉

    drop user ABC cascade;

    --删除表空间,及对应的表空间文件也删除掉

    drop tablespace ABC including contents and datafiles cascade constraint;

    删除无任何数据对象的表空间:

    首先使用PL/SQL界面化工具,或者使用oracle自带的SQL PLUS工具,连接需要删除的表空间的oracle数据局库。

    确认当前用户是否有删除表空间的权限,如果没有 drop tablespace,请先用更高级的用户(如sys)给予授权或者直接用更高级的用户。

    用drop tablespace xxx ,删除需要删除的表空间。

    删除有任何数据对象的表空间

    使用drop tablespace xxx including contents and datafiles;来删除表空间。

    注意事项:

    如果drop tablespace语句中含有datafiles,那datafiles之前必须有contents关键字,不然会提示ora-01911错误

    1、以system用户登录查找需要删除的用户(普通用户没有删除权限)

    select * from dba_users;

    2、查询需要删除用户对应的表空间

    select * from dba_data_files;

    3、删除用户和表空间

    drop user usernamecascade;

    drop tablespace tablespacename including contents and datafiles cascade constraint;

    在删除用户时可能会碰到无法删除当前连接的用户,这是由于还有数据库连接到该用户,有会话存在,需要先删除会话。

    最暴力的做法是直接shutdown数据库,然后重启即可。。。

    一般的操作是通过查询SessionID,手动杀掉会话再删除用户:

    1)查询连接情况:select username,sid,serial# from v$session;

    2)找到要删除用户的sid和serial并删除:alter system kill session 'sid,serial';

    再执行删除用户的操作,如果还是无法删除说明还有连接的会话,继续执行删除会话的操作。

    ---------------------

    展开全文
  • 主要介绍了使用shell脚本操作oracle删除表空间、创建表空间、删除用户的方法,需要的朋友可以参考下
  • 回滚段是数据库的一部分,它记录数据库变更的信息。使用这些信息实现数据库的读一致性及其恢复。若回滚段出现故障,则数据库不能正常启动,导致数据库瘫痪,...本文将为大家介绍Oracle回滚表空间数据文件误删除处理。
  • oracle表数据已经删除,但是表空间不能释放的情况;支持查询单占用空间大小,释放掉占用的无效空间;支持批量生成释放脚本,释放掉空占用的表空间
  • /*第1步:创建临时表空间 */ /*第2步:创建数据表空间 */ /*第3步:创建用户并指定表空间 注意新建的oracle用户必须以C##开头*/ /*第4步:给用户授予权限 */
  • Oracle 删除用户和表空间 Oracle 使用时间长了, 新增了许多user 和tablespace. 需要清理一下 对于单个user和tablespace 来说, 可以使用如下命令来完成。  步骤一: 删除user drop user ×× cascade 说明: ...
  • Oracle释放临时表空间脚本
  • 主要介绍了Linux下Oracle删除用户和表空间的方法,涉及Oracle数据库用户和操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
  • 如何正确的删除表空间数据文件

    千次阅读 2021-05-02 07:05:54
    如何正确的删除表空间数据文件应该使用如下的命令删除:ALTER TABLESPACE TEST DROP DATAFILE3;参考mos文章:Unable to Drop a Datafile From the Tablespace Using Alter Tablespace Command (文档ID 1050261.1)...

    如何正确的删除表空间数据文件

    应该使用如下的命令删除:

    ALTER TABLESPACE TEST DROP DATAFILE3;

    参考mos文章:

    Unable to Drop a Datafile From the Tablespace Using Alter Tablespace Command (文档ID 1050261.1)

    违反下列任何一个条件,该datafile均不能被drop:

    1)必须为空,否则会报:ORA-03262: the file is non-empty。值得注意的是,non-empty的含义是有extent被分配给了table,而不是该table中有无rows,此时若是使用drop table xxx是不行的,必须使用drop table xxx purge;或者在已经使用了drop table xxx的情况下,再使用purge table “xxx表在回收站中的名称”来purge该表,否则空间还是不释放,datafile依然drop不掉。

    2)不能是所属表空间的第一个file

    以上两者可以通过drop tablespace来达到目的。

    3)不能在read-only表空间中。---经测试是可以的

    4)不能被offline,否则会报:ORA-03264: cannot drop offline datafile of locally managed tablespace

    针对该报错,解决方法为:

    [oracle@rhel6 u01]$ oerr ora 3264

    03264, 00000, "cannot drop offline datafile of locally managed tablespace"

    // *Cause:  Trying to drop offline datafile in lmts

    // *Action: Try to drop file afetr making it online

    5)Cannot be a datafile that is part of the system tablespace, even if it is not the first datafile of the system tablespace--该条来源于How to Drop a Datafile From a Tablespace (文档ID 111316.1)

    若使用alter database datafile 3 offline drop;并不会删除数据文件,这个时候可以先online后再用alter tablespace test drop datafile 3;删除,若执行alter database  datafile 3 offline drop;后并OS级别删除了数据文件,那么需要使用alter database create datafile 3 as '/u03/app/oracle/oradata/ora1024g/sysaux01.dbf';来添加一个数据文件,然后再执行recover并online后再用alter tablespace test drop datafile 3;命令删除。

    1. alter database datafile 'file_name' offline drop

    该命令不会删除数据文件,只是将数据文件的状态更改为recover。 offline drop命令相当于把一个数据文件至于离线状态,并且需要恢复,并非删除数据文件。 数据文件的相关信息还会存在数据字典和控制文件中。

    1.1 对于归档模式:

    alter database datafile 'file_name' offline 和 offline drop 没有什么区别。 因为offline 之后多需要进行recover 才可以online。

    如:

    SQL>ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' OFFLINE;

    SQL>ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' ONLINE;

    1.2 对于非归档模式:

    如果是非归档模式,只能是offline drop. 因为非归档模式没有归档文件来进行recover操作,当然,如果offline 之后,速度足够块,online redo里的数据还没有被覆盖掉,那么这种情况下,还是可以进行recover的。

    oracle 11g:

    SQL>ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/users03.dbf' OFFLINE FOR DROP;

    2. alter tablesapce ‘tablespace_name’ drop datafile 'datafile_name'

    该语句会删除磁盘上的文件并更新控制文件和数据字典中的信息,删除之后的原数据文件序列号可以重用。

    注意,该语句只能是datafile online的时候才可以使用。如果说对应的数据文件已经是offline for drop,那么仅针对 dictionary managed tablespaces 可用。

    OFFLINESpecify OFFLINE to take the data file offline. If the database is open,

    then you must perform media recovery on the data file before bringing it back

    online, because a checkpoint is not performed on the data file before it is

    taken offline.

    FOR DROPIf

    the database is in NOARCHIVELOG mode, then you must specify FOR DROP clause to take a data file offline. However,

    this clause does not remove the data file from the database. To do that, you

    must use an operating system command or drop the tablespace in which the data

    file resides. Until you do so, the data file remains in the data dictionary with

    the status RECOVER or OFFLINE.

    If the database is in ARCHIVELOG mode, then Oracle Database

    ignores the FOR DROP clause.

    Bringing Data Files Online or Taking Offline in ARCHIVELOG

    Mode

    To bring an individual data file online,

    issue the ALTER DATABASE statement and include the DATAFILE clause. The following statement brings the specified data

    file online:

    ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' ONLINE;

    To take the same file offline, issue the following statement:

    ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' OFFLINE;

    Note:

    To use this form of the ALTER DATABASE statement, the database must be in ARCHIVELOG mode. This

    requirement prevents you from accidentally losing the data file, since taking

    the data file offline while in NOARCHIVELOG mode is likely to

    result in losing the file.

    Taking Data Files Offline in NOARCHIVELOG Mode

    To take a data file offline when the database

    is in NOARCHIVELOG mode, use the ALTER DATABASE statement with both the DATAFILE and OFFLINE FOR DROP clauses.

    The OFFLINE keyword causes the database to mark the data file OFFLINE, whether or not it is corrupted, so that you can open the

    database.

    The FOR DROP keywords mark the data file for

    subsequent dropping. Such a data file can no longer be brought back online.

    Note:

    This operation does not actually drop the data file. It

    remains in the data dictionary, and you must drop it yourself using one of the

    following methods:

    An ALTER TABLESPACE ... DROP DATAFILE statement.

    After an OFFLINE FOR DROP, this method works for dictionary managed

    tablespaces only.

    A DROP TABLESPACE ... INCLUDING CONTENTS AND DATAFILES statement

    If the preceding methods fail, an operating system command to delete the data

    file. This is the least desirable method, as it leaves references to the data

    file in the data dictionary and control files.

    The following statement takes the specified data file offline and marks it to

    be dropped:

    ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/users03.dbf' OFFLINE FOR DROP;

    点击(此处)折叠或打开

    SYS@ora10g> create tablespace ts_dd_lhr datafile '/tmp/ts_dd_lhr01.dbf' size 10M;

    Tablespace created.

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf'

    *

    ERROR at line 1:

    ORA-03261: the tablespace TS_DD_LHR has only one file

    SYS@ora10g> alter tablespace ts_dd_lhr add datafile '/tmp/ts_dd_lhr02.dbf' size 10M;

    Tablespace altered.

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf'

    *

    ERROR at line 1:

    ORA-03263: cannot drop the first file of tablespace TS_DD_LHR

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    Tablespace altered.

    SYS@ora10g> ! ls -l /tmp/ts_dd_lhr0*

    -rw-r----- 1 oracle oinstall 10493952 Jun 29 14:58 /tmp/ts_dd_lhr01.dbf

    --------------------------------------------------

    SYS@ora10g> alter tablespace ts_dd_lhr add datafile '/tmp/ts_dd_lhr02.dbf' size 10M;

    Tablespace altered.

    SYS@ora10g> alter database datafile '/tmp/ts_dd_lhr02.dbf' offline drop;

    Database altered.

    SYS@ora10g> ! ls -l /tmp/ts_dd_lhr02.dbf

    -rw-r----- 1 oracle oinstall 10493952 Jun 29 15:17 /tmp/ts_dd_lhr02.dbf

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf'

    *

    ERROR at line 1:

    ORA-03264: cannot drop offline datafile of locally managed tablespace

    SYS@ora10g> alter database datafile '/tmp/ts_dd_lhr02.dbf' online;

    alter database datafile '/tmp/ts_dd_lhr02.dbf' online

    *

    ERROR at line 1:

    ORA-01113: file 9 needs media recovery

    ORA-01110: data file 9: '/tmp/ts_dd_lhr02.dbf'

    SYS@ora10g> recover datafile 9;

    Media recovery complete.

    SYS@ora10g> alter database datafile '/tmp/ts_dd_lhr02.dbf' online;

    Database altered.

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    Tablespace altered.

    SYS@ora10g> ! ls -l /tmp/ts_dd_lhr02.dbf

    ls: cannot access /tmp/ts_dd_lhr02.dbf: No such file or directory

    SYS@orclasm > create table t_ts_dd_lhr tablespace ts_dd_lhr as select * from dual;

    Table created.

    SYS@orclasm > truncate table t_ts_dd_lhr;

    Table truncated.

    SYS@orclasm >

    SYS@orclasm > alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf'

    *

    ERROR at line 1:

    ORA-03262: the file is non-empty

    SYS@orclasm > drop table t_ts_dd_lhr;

    Table dropped.

    SYS@orclasm > alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf'

    *

    ERROR at line 1:

    ORA-03262: the file is non-empty

    SYS@orclasm > purge recyclebin;

    Recyclebin purged.

    SYS@orclasm > alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    Tablespace altered.

    SYS@ora10g> create tablespace ts_dd_lhr datafile '/tmp/ts_dd_lhr01.dbf' size 10M;

    alter tablespace ts_dd_lhr add datafile '/tmp/ts_dd_lhr02.dbf' size 10M;

    Tablespace created.

    SYS@ora10g> SYS@ora10g> SYS@ora10g>

    Tablespace altered.

    SYS@ora10g>

    SYS@ora10g> alter tablespace ts_dd_lhr read only;

    Tablespace altered.

    SYS@ora10g> select * from dba_tablespaces;

    TABLESPACE_NAME BLOCK_SIZE INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE MIN_EXTLEN STATUS CONTENTS LOGGING FOR EXTENT_MAN ALLOCATIO PLU SEGMEN DEF_TAB_ RETENTION BIG

    ------------------------------ ---------- -------------- ----------- ----------- ----------- ------------ ---------- --------- --------- --------- --- ---------- --------- --- ------ -------- ----------- ---

    SYSTEM 8192 65536 1 2147483645 65536 ONLINE PERMANENT LOGGING NO LOCAL SYSTEM NO MANUAL DISABLED NOT APPLY NO

    UNDOTBS1 8192 65536 1 2147483645 65536 ONLINE UNDO LOGGING NO LOCAL SYSTEM NO MANUAL DISABLED NOGUARANTEE NO

    SYSAUX 8192 65536 1 2147483645 65536 ONLINE PERMANENT LOGGING NO LOCAL SYSTEM NO AUTO DISABLED NOT APPLY NO

    TEMP 8192 1048576 1048576 1 0 1048576 ONLINE TEMPORARY NOLOGGING NO LOCAL UNIFORM NO MANUAL DISABLED NOT APPLY NO

    USERS 8192 65536 1 2147483645 65536 ONLINE PERMANENT LOGGING NO LOCAL SYSTEM NO AUTO DISABLED NOT APPLY NO

    EXAMPLE 8192 65536 1 2147483645 65536 ONLINE PERMANENT NOLOGGING NO LOCAL SYSTEM YES AUTO DISABLED NOT APPLY NO

    TS10GTEST 8192 65536 1 2147483645 65536 ONLINE PERMANENT LOGGING NO LOCAL SYSTEM NO AUTO DISABLED NOT APPLY NO

    HHRIS 8192 65536 1 2147483645 65536 ONLINE PERMANENT LOGGING NO LOCAL SYSTEM NO AUTO DISABLED NOT APPLY NO

    TS_DD_LHR 8192 65536 1 2147483645 65536 READ ONLY PERMANENT LOGGING NO LOCAL SYSTEM NO AUTO DISABLED NOT APPLY NO

    9 rows selected.

    SYS@ora10g>

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf';

    alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr01.dbf'

    *

    ERROR at line 1:

    ORA-03263: cannot drop the first file of tablespace TS_DD_LHR

    SYS@ora10g>

    SYS@ora10g> alter tablespace ts_dd_lhr drop datafile '/tmp/ts_dd_lhr02.dbf';

    Tablespace altered.

    SQL> select * from v$version;

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

    PL/SQL Release 10.2.0.1.0 - Production

    CORE    10.2.0.1.0      Production

    TNS for Linux: Version 10.2.0.1.0 - Production

    NLSRTL Version 10.2.0.1.0 - Production

    SQL> select name from v$datafile;

    NAME

    ------------------------------------------------------------------------------

    +DATA/rac/datafile/system.256.746634087

    +DATA/rac/datafile/undotbs1.258.746634089

    +DATA/rac/datafile/sysaux.257.746634087

    +DATA/rac/datafile/users.259.746634089

    +DATA/rac/datafile/undotbs2.264.746634255

    SQL> create tablespace test datafile '+DATA/rac/datafile/test01.dbf' size 10M;

    Tablespace created.

    SQL> alter tablespace test add datafile '+DATA/rac/datafile/test02.dbf' size 10M;

    Tablespace altered.

    SQL> select file#,status,name from v$datafile;

    FILE# STATUS  NAME

    ---------- ------- -----------------------------------------------------------

    1 SYSTEM  +DATA/rac/datafile/system.256.746634087

    2 ONLINE  +DATA/rac/datafile/undotbs1.258.746634089

    3 ONLINE  +DATA/rac/datafile/sysaux.257.746634087

    4 ONLINE  +DATA/rac/datafile/users.259.746634089

    5 ONLINE  +DATA/rac/datafile/undotbs2.264.746634255

    6 ONLINE +DATA/rac/datafile/test01.dbf

    7 ONLINE  +DATA/rac/datafile/test02.dbf

    SQL> alter database datafile '+DATA/rac/datafile/test01.dbf' offline;

    Database altered.

    SQL> set wrap off;

    SQL> select file#,status,name from v$datafile;

    FILE# STATUS  NAME

    ---------- ------- -----------------------------------------------------------

    1 SYSTEM  +DATA/rac/datafile/system.256.746634087

    2 ONLINE  +DATA/rac/datafile/undotbs1.258.746634089

    3 ONLINE  +DATA/rac/datafile/sysaux.257.746634087

    4 ONLINE  +DATA/rac/datafile/users.259.746634089

    5 ONLINE  +DATA/rac/datafile/undotbs2.264.746634255

    6 RECOVER +DATA/rac/datafile/test01.dbf

    7 ONLINE  +DATA/rac/datafile/test02.dbf

    7 rows selected.

    SQL> alter tablespace test drop datafile 6;

    alter tablespace test drop datafile 6

    *

    ERROR at line 1:

    ORA-03263: cannot drop the first file of tablespace TEST

    这里报错了,因为datafile 6是test表空间第一个数据文件不让删(这种情况只能删表空间了)。 我们删除test02.dbf 看看

    SQL> alter tablespace test drop datafile 7;

    Tablespace altered.

    -- 删除成功。

    SQL> select file#,status,name from v$datafile;

    FILE# STATUS  NAME

    ---------- ------- -----------------------------------------------------------

    1 SYSTEM  +DATA/rac/datafile/system.256.746634087

    2 ONLINE  +DATA/rac/datafile/undotbs1.258.746634089

    3 ONLINE  +DATA/rac/datafile/sysaux.257.746634087

    4 ONLINE  +DATA/rac/datafile/users.259.746634089

    5 ONLINE  +DATA/rac/datafile/undotbs2.264.746634255

    6 RECOVER +DATA/rac/datafile/test01.dbf

    6 rows selected.

    去ASM 里看下物理文件是否删除掉了:

    [oracle@rac1 ~]$ export ORACLE_SID=+ASM1

    [oracle@rac1 ~]$ asmcmd

    ASMCMD> ls

    DATA/

    FRA/

    ASMCMD> cd DATA

    ASMCMD> ls

    TEST/

    DB_UNKNOWN/

    RAC/

    ASMCMD> cd RAC

    ASMCMD> ls

    CONTROLFILE/

    DATAFILE/

    TEMPFILE/

    spfiletest.ora

    spfilerac.ora

    ASMCMD> cd DATAFILE

    ASMCMD> ls

    SYSAUX.257.746634087

    SYSTEM.256.746634087

    UNDOTBS1.258.746634089

    UNDOTBS2.264.746634255

    USERS.259.746634089

    test01.dbf

    --对应的物理文件test02.dbf 已经被删除了

    我们将datafile 6 online 看看:

    SQL> alter database datafile 6 online;

    alter database datafile 6 online

    *

    ERROR at line 1:

    ORA-01113: file 6 needs media recovery

    ORA-01110: data file 6: '+DATA/rac/datafile/test01.dbf'

    --提示需要recover。 这也就是需要归档文件的原因。

    SQL> recover datafile 6;

    Media recovery complete.

    SQL> alter database datafile 6 online;

    Database altered.

    SQL> select file#,status,name from v$datafile;

    FILE# STATUS  NAME

    ---------- ------- -----------------------------------------------------------

    1 SYSTEM  +DATA/rac/datafile/system.256.746634087

    2 ONLINE  +DATA/rac/datafile/undotbs1.258.746634089

    3 ONLINE  +DATA/rac/datafile/sysaux.257.746634087

    4 ONLINE  +DATA/rac/datafile/users.259.746634089

    5 ONLINE  +DATA/rac/datafile/undotbs2.264.746634255

    6 ONLINE  +DATA/rac/datafile/test01.dbf

    6 rows selected.

    最后把整个表空间test drop 掉:

    SQL> drop tablespace test including contents and datafiles;

    Tablespace dropped.

    SQL> select file#,status,name from v$datafile;

    FILE# STATUS  NAME

    ---------- ------- -----------------------------------------------------------

    1 SYSTEM  +DATA/rac/datafile/system.256.746634087

    2 ONLINE  +DATA/rac/datafile/undotbs1.258.746634089

    3 ONLINE  +DATA/rac/datafile/sysaux.257.746634087

    4 ONLINE  +DATA/rac/datafile/users.259.746634089

    5 ONLINE  +DATA/rac/datafile/undotbs2.264.746634255

    去ASM里看一下:

    ASMCMD> ls

    SYSAUX.257.746634087

    SYSTEM.256.746634087

    UNDOTBS1.258.746634089

    UNDOTBS2.264.746634255

    USERS.259.746634089

    对应的物理文件没有了。

    SQL>alter tablespace test drop datafile 8;

    不能drop 非空的数据文件, 如果要drop 某个数据文件,需要先把对象移除走。

    SELECT owner ownr,

    segment_name name,

    segment_type TYPE,

    extent_id exid,

    file_id fiid,

    block_id blid,

    blocks blks

    FROM dba_extents

    WHERE file_id = 8

    ORDER BY block_id;

    alter table temp move tablespace test2; 重建索引。

    Unable to Drop a Datafile From the Tablespace Using Alter Tablespace Command (文档 ID 1050261.1)

    In this Document

    This document is being delivered to you via Oracle Support's Rapid Visibility (RaV) process and therefore has not been subject to an independent technical review.

    APPLIES TO:

    Oracle Database - Enterprise Edition - Version 10.2.0.1 to 11.2.0.1.0 [Release 10.2 to 11.2]

    Information in this document applies to any platform.

    ***Checked for relevance on 01-Nov-2011***

    ***Checked for relevance on 27-Aug-2014***

    SYMPTOMS

    Attempting to drop a datafile from a tablespace using the 10.2 and higher feature:

    alter tablespace ... drop datafile ... ;

    fails. The errors reported may differ depending on the actual situation.

    ORA-3262: the file is non-empty

    ORA-3263: cannot drop the first file of tablespace

    ORA-3264: cannot drop offline datafile of locally managed tablespace

    ORA-60

    Some errors are rather straightforward. However some errors are not, like the ORA-60. While the answer to the most common errors are self explanatory, this note focuses on the ORA-60 self-deadlock error received..

    CHANGES

    Datafile was lost at the Operating System level, causing the datafile to be in an OFFLINE status. Because the datafile contained some temporary segments and extents, these became invalid or stray. This causes an ORA-60 when trying to drop the datafile from the tablespace.

    The datafile may be listed as MISSING in the datafile name, the reason for this is explained in:

    Note 1050268.1: Explanation of MISSING keyword in datafile name

    CAUSE

    To drop a data file or temp file, it:

    - Must be empty.

    - Cannot be the first file that was created in the tablespace.

    In such cases, drop the tablespace instead.

    - Cannot be in a read-only tablespace.

    - Cannot be offline.

    SOLUTION

    The missing datafile has left this tablespace in an indeterminate status. The tablespace itself can actually still be used. But when an object located in the missing datafile is accessed, the statement will error-out with:

    ORA-376: file 7 cannot be read at this time

    The tablespace will need to be dropped as well. The 10gR2 feature to drop a single datafile from a tablespace cannot be use in this situation..

    The following notes can be used to recover the data:

    Note 216683.1: How to Recover Data from a Tablespace When One or Several Datafiles are Lost.

    Note 286355.1: How to Recover OFFLINE Dropped Datafile in ARCHIVELOG MODE

    REFERENCES

    NOTE:1050268.1- Explanation of MISSING keyword in datafile name

    NOTE:286355.1- HOW TO RECOVER OFFLINE DROPPED DATAFILE IN ARCHIVELOG MODE

    How to Drop a Datafile From a Tablespace (文档 ID 111316.1)

    PURPOSE

    This note explains how a datafile can be removed from a database.

    Since there can be confusion as to how a datafile can be dropped because of

    the ALTER DATABASE DATAFILE OFFLINE DROP command, this note explains the

    steps needed to delete a datafile and, in contrast, when the OFFLINE DROP

    command is used.

    SCOPE & APPLICATION

    There are two situations where people may want to 'remove' a datafile from a

    tablespace:

    1. You have just mistakenly added a file to a tablespace, or perhaps you

    made the file much larger than intended and now want to remove it.

    2. You are involved in a recovery scenario and the database will not start

    because a datafile is missing.

    This article is meant to discuss situation 1 above. There are other

    articles that discuss recovery scenarios where a database cannot be brought

    online due to missing datafiles. Please see the 'Related Documents' section

    at the bottom of this article.

    Restrictions on Dropping Datafiles:

    - Datafile Must be empty.

    - Cannot be the first file in the tablespace. In such cases, drop the tablespace instead.

    - Cannot be a datafile that is part of the system tablespace, even if it is not the first datafile of the system tablespace.

    - Cannot be in a read-only tablespace.

    - The datafile cannot be offline.

    How to 'DROP' a Datafile from a Tablespace:

    ===========================================

    Version 9.2 and earlier

    Before we start with detailed explanations of the process involved, please note

    that Oracle does not provide an interface for dropping datafiles in the same

    way that you could drop a schema object such as a table, a view, a user, etc.

    Once you make a datafile part of a tablespace, the datafile CANNOT be removed,

    although we can use some workarounds.

    Before performing certain operations such as taking tablespaces/datafiles

    offline, and trying to drop them, ensure you have a full backup.

    If the datafile you wish to remove is the only datafile in that tablespace,

    simply drop the entire tablespace using:

    DROP TABLESPACE INCLUDING CONTENTS;

    You can confirm how many datafiles make up a tablespace by running the

    following query:

    select file_name, tablespace_name

    from dba_data_files

    where tablespace_name ='';

    The DROP TABLESPACE command removes the tablespace, the datafile, and the

    tablespace's contents from the data dictionary. Oracle will no longer have

    access to ANY object that was contained in this tablespace. The physical

    datafile must then be removed using an operating system command (Oracle NEVER

    physically removes any datafiles). Depending on which platform you try this

    on, you may not be able to physically delete the datafile until Oracle is

    completely shut down. (For example, on Windows NT, you may have to shutdown

    Oracle AND stop the associated service before the operating system will allow

    you to delete the file - in some cases, file locks are still held by Oracle.)

    If you have more than one datafile in the tablespace, and you do NOT need the

    information contained in that tablespace, or if you can easily recreate the

    information in this tablespace, then use the same command as above:

    DROP TABLESPACE INCLUDING CONTENTS;

    Again, this will remove the tablespace, the datafiles, and the tablespace's

    contents from the data dictionary. Oracle will no longer have access to ANY

    object that was contained in this tablespace. You can then use CREATE

    TABLESPACE and re-import the appropriate objects back into the tablespace.

    If you have more than one datafile in the tablespace and you wish to keep the

    objects that reside in the other datafile(s) which are part of this tablespace,

    then you must export all the objects inside the affected tablespace. Gather

    information on the current datafiles within the tablespace by running this

    query:

    select file_name, tablespace_name

    from dba_data_files

    where tablespace_name ='';

    Make sure you specify the tablespace name in capital letters.

    In order to allow you to identify which objects are inside the affected

    tablespace for the purposes of running your export, use the following query:

    select owner,segment_name,segment_type

    from dba_segments

    where tablespace_name=''

    Now, export all the objects that you wish to keep.

    Once the export is done, issue the DROP TABLESPACE tablespace INCLUDING

    CONTENTS.

    Note that this PERMANENTLY removes all objects in this tablespace. Delete the

    datafiles belonging to this tablespace using the operating system. (See the

    comment above about possible problems in doing this.) Recreate the tablespace

    with the datafile(s) desired, then import the objects into that tablespace.

    (This may have to be done at the table level, depending on how the tablespace

    was organized.)

    NOTE:

    The ALTER DATABASE DATAFILE OFFLINE DROP command, is not meant

    to allow you to remove a datafile. What the command really means is that you

    are offlining the datafile with the intention of dropping the tablespace.

    If you are running in archivelog mode, you can also use:

    ALTER DATABASE DATAFILE OFFLINE;

    instead of OFFLINE DROP. Once the datafile is offline, Oracle no longer

    attempts to access it, but it is still considered part of that tablespace. This

    datafile is marked only as offline in the controlfile and there is no SCN

    comparison done between the controlfile and the datafile during startup (This

    also allows you to startup a database with a non-critical datafile missing).

    The entry for that datafile is not deleted from the controlfile to give us the

    opportunity to recover that datafile.

    New functionality was added with the release of version 10.1 and higher

    You can now specify drop tablespace inlcluding contents AND DATAFILES

    Refer to Oracle? Database Administrator's Guide 10g Release 1 (10.1) Part Number B10739-01

    Chapter 8 managing tablespaces for more detailed explination

    Starting with version 10.2 and higher

    You can now alter tablespace drop datafile (except first datafile

    of a tablespace)

    Refer to the following Oracle Documentation for more details regarding this operation:

    For Oracle 10g Release 2:

    Oracle? Database Administrator's Guide 10g Release 2 (10.2)Part Number B14231-02 Chapter 9: Dropping Datafiles.

    For Oracle 11g:

    Oracle? Database Administrator's Guide 11g Release 1 (11.1) Part Number B28310-04 Chapter 12: Dropping Datafiles.

    If you do not wish to follow any of these procedures, there are other things

    that can be done besides dropping the tablespace.

    - If the reason you wanted to drop the file is because you mistakenly created

    the file of the wrong size, then consider using the RESIZE command.

    See 'Related Documents' below.

    - If you really added the datafile by mistake, and Oracle has not yet allocated

    any space within this datafile, then you can use ALTER DATABASE DATAFILE

    RESIZE; command to make the file smaller than 5 Oracle blocks. If

    the datafile is resized to smaller than 5 oracle blocks, then it will never

    be considered for extent allocation. At some later date, the tablespace can

    be rebuilt to exclude the incorrect datafile.

    RELATED DOCUMENTS

    ----------------- Note 30910.1 - Recreating database objects Note 1013221.6 - Recovering from a lost datafile in a ROLLBACK tablespace Note 198640.1 - How to Recover from a Lost Datafile with Different Scenarios Note 1060605.6 - Recover A Lost Datafile With No Backup Note 1029252.6 - How to resize a datafile

    HOW TO RECOVER OFFLINE DROPPED DATAFILE IN ARCHIVELOG MODE (文档 ID 286355.1)

    The information in this document applies to:

    Symptoms

    You have offline dropped a datafile in archivelog mode

    You know that once you drop a datafile you need to recreate the tablespace containing that datafile

    You can not do that as this is a Big tablespace

    You want that datafile to be again part of the database

    even though you do not want that datafile to contain any objects

    Changes

    You can recover the offline datafile and then make it online

    further as you do not want any objects to be allocated to that datafile

    you can resize it to a very small size ( remember it can only be done if the datafile is empty .........

    you can not resize a datafile below it's high water mark)

    Example

    ==========

    SQL> archive log list

    Database log mode Archive Mode

    Automatic archival Enabled

    Archive destination /h01/app/oracle/product/9.2.0/dbs/arch

    Oldest online log sequence 207

    Next log sequence to archive 209

    Current log sequence 209

    =======================

    shows DB is in archivelog mode

    =======================

    SQL> alter database datafile 44 offline drop;

    Database altered.

    SQL> select file#,status from v$datafile where file#=44;

    FILE# STATUS

    ---------- -------

    44 RECOVER ======> status in controlfile is recover

    SQL> c/datafile/datafile_header

    1* select file#,status from v$datafile_header where file#=44

    SQL> /

    FILE# STATUS

    ---------- -------

    44 OFFLINE ========> status in file_header is offline

    switch some log file

    sql> alter system switch logfile ;

    system altered

    .

    .

    .

    apply the log ( it will only ask for the log/ corresponding archivelog which was

    online at that time

    It wont ask you to apply any other archivelog

    SQL> recover datafile 44;

    ORA-00279: change 8252199007514 generated at 10/18/2004 14:21:47 needed for thread 1

    ORA-00289: suggestion : /h01/app/oracle/product/9.2.0/dbs/arch1_216.dbf

    ORA-00280: change 8252199007514 for thread 1 is in sequence #216

    Specify log: {=suggested | filename | AUTO | CANCEL}

    Log applied.

    Media recovery complete.

    SQL> select * from v$log;

    GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM

    ---------- ---------- ---------- ---------- ---------- --- ----------- ------------- ---------

    1 1 248 104857600 1 YES INACTIVE 8.2522E+12 18-OCT-04

    2 1 250 104857600 1 NO CURRENT 8.2522E+12 18-OCT-04

    3 1 249 104857600 1 YES ACTIVE 8.2522E+12 18-OCT-04

    SQL> select file#,status from v$datafile where file#=44;

    FILE# STATUS

    ---------- -------

    44 OFFLINE

    SQL> select file#,status from v$datafile_header where file#=44;

    FILE# STATUS

    ---------- -------

    44 OFFLINE

    SQL> alter database datafile 44 online;

    Database altered.

    SQL> select file#,status from v$datafile_header where file#=44;

    FILE# STATUS

    ---------- -------

    44 ONLINE

    SQL> select file#,status from v$datafile where file#=44;

    FILE# STATUS

    ---------- -------

    44 ONLINE

    SO the datafile is online

    The only case in which the offline dropped datafile can not be online is

    when you have added to many datafiles in the database after offline drop

    Cause

    From Documentation

    ====================

    If the database is in NOARCHIVELOG mode, you must specify the DROP clause to take a datafile

    offline. However, the DROP clause does not remove the datafile from the database.

    To do that, you must drop the tablespace in which the datafile resides. Until you

    do so, the datafile remains in the data dictionary with the status RECOVER or OFFLINE.

    If the database is in ARCHIVELOG mode, Oracle ignores the DROP keyword.

    展开全文
  • oracle 12c删除表空间

    千次阅读 2020-10-14 12:05:02
    删除表空间语句如下: --删除空的表空间,但是不包含物理文件 drop tablespace tablespace_name; --删除非空表空间,但是不包含物理文件 drop tablespace tablespace_name including contents; --删除表空间,包含...

    删除表空间语句如下:

    --删除空的表空间,但是不包含物理文件
    drop tablespace tablespace_name;
    --删除非空表空间,但是不包含物理文件
    drop tablespace tablespace_name including contents;
    --删除空表空间,包含物理文件
    drop tablespace tablespace_name including datafiles;
    --删除非空表空间,包含物理文件
    drop tablespace tablespace_name including contents and datafiles;
    --如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS
    drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
    

    但实际情况并不是那么简单。当然啦,oracle嘛,跟java一样,总会比较折腾,都习惯了。如果顺风顺水,反而不正常。

    以下是真实操作记录,一切尽在不言中:

    SQL> drop tablespace sde_tbs including contents and datafiles;
    drop tablespace sde_tbs including contents and datafiles
    *1 行出现错误:
    ORA-29857: 表空间中存在域索引和/或次级对象
    
    
    SQL> drop user sde cascade;
    drop user sde cascade
    *1 行出现错误:
    ORA-01940: 无法删除当前连接的用户
    
    
    SQL> select username,sid,serial# from v$session where username='SDE';
    
    USERNAME                              SID    SERIAL#
    ------------------------------ ---------- ----------
    SDE                                   202      65426
    SDE                                   581      30637
    
    SQL> alter system kill session'202,65426';
    
    系统已更改。
    
    SQL> alter system kill session'581,30637';
    
    系统已更改。
    
    SQL> drop user sde cascade;
    
    用户已删除。
    
    SQL> drop tablespace sde_tbs including contents and datafiles;
    
    表空间已删除。
    
    SQL>
    

    参考文章:
    oracle 删除表空间及数据文件方法

    展开全文
  • 1)批量将niptest表空间中的move到USERS表空间,再删除表空间niptest首先看下此表空间内的move到其他表空间防止数据丢失select * from dba_tables where tablespace_name='NIPTEST';select * from dba_extents ...
  • Oracle 删除用户和表空间

    千次阅读 2021-05-08 04:17:11
    版权声明:本文为博主原创文章,未经博主允许不得转载。...步骤一: 删除userdrop user ×× cascade说明: 删除了user,只是删除了该user下的schema objects,是不会删除相应的tablespace的。步骤二...
  • oracle定时删除表空间数据并释放表空间(oracle编程高手总结编写)
  • 但不能修改系统表空间system与sysaOracle重命名表空间删除表空间[日期:2015-03-10]来源:Linux社区作者:理央silence[字体:]在需要的情况下,可以对表空间的名称进行修改。修改表空间的名称,,不会影响到表空间...
  • Oracle 如何删除表空间

    千次阅读 2022-05-31 11:54:28
    1、删除无任何数据对象的表空间: 用drop tablespace xxx ,删除需要删除表空间。 2、删除有任何数据对象的表空间 使用drop tablespace xxx including contents and datafiles;
  • 小文件表空间smallfile tablespace Oracle数据文件的大小存在一个内部限制每个数据文件最多只能包含2^22-1个数据块 这个限制是由于Oracle的Rowid中使用22位来代表Block号这22位最多只能代表2^22-1个数据块 在K Block...
  • Oracle如何删除表空间

    千次阅读 2021-06-14 11:08:34
    很多小伙伴在刚刚学习Oracle的时候,想要删除不要的表空间。但很多情况下,没有进行正确的操作,这个就会导致Oracle无法使用,那如何正确的删除表空间呢?具体的操作如下:
  • 简单说下原因:当时图方便没进数据库,直接在datafile目录下删除表空间对应的数据文件导致后来数据库报错,并且不能删除表空间错误如下;ORA-01116:error in opening database ****ORA-01110:data file 54:'/home3...
  • 主要介绍了Oracle删除表及查看表空间的实例详解,非常不错,具有参考借鉴价值,需要的朋友可以参考下
  • Oracle7.X 回滚表空间数据文件误删除处理方法
  • 本文讲述了Oracle修改表空间大小的方法。分享给大家供大家参考,具体如下: 1)查看各表空间分配情况 SQL> select tablespace_name, sum(bytes) / 1024 / 1024 from dba_data_files group by tablespace_name; ...
  • 文章目录前言一、分区表删除二、表空间删除二、表空间删除 前言 记录一些oracle常规操作不一样的地方 一、分区表删除 -- 删除指定分区数据 delete from TABLE_NAME partition(TABLE_PARTITION_NAME); --删除分区 ...
  • 删除Oracle Undo表空间

    千次阅读 2021-05-06 09:37:49
    近期处理了一次删除、重建Undo表空间的事情,有些细节还是值得记下来备忘。事情的起因是工程师需要将分布在不同ASM磁盘组里的Oracle数据库文件,迁移到新建的ASM磁盘组,操作过程中,错误的删除了Undo磁盘组的所有...
  • oracle 11G创建表空间、用户、密码、索引、分配权限、删除表空间数据泵导入、导出

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 153,405
精华内容 61,362
关键字:

oracle删除表空间数据