zoukankan      html  css  js  c++  java
  • ORACLE表空间offline谈起,表空间备份恢复

    从ORACLE表空间offline谈起,表空间备份恢复
    将表空间置为offline,可能的原因包括维护、备份恢复等目的;
    表空间处于offline状态,那么Oracle不会允许任何对该表空间中对象的SQL执行,表空间置为offline时仍处于活动状态的语句在交易级别并不会受影响。

    实验一:RMAN备份恢复表空间
    SQL> create tablespace test datafile '/data/app/oracle/oradata/ORCL/datafile/test01.dbf' size 1G ;
    Tablespace created.
    SQL> alter tablespace TEST add datafile '/data/app/oracle/oradata/ORCL/datafile/test02.dbf' size 1G;
    Tablespace altered.
    [oracle@prod ~]$ rman target /
    Recovery Manager: Release 12.1.0.2.0 - Production on Thu Jun 14 11:26:31 2018
    Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
    connected to target database: ORCL (DBID=1607304684)

    RMAN> backup tablespace "TEST" tag "test";
    RMAN> alter tablespace test offline;
    模拟数据文件损坏
    [oracle@prod ~]$ mv /data/app/oracle/oradata/ORCL/datafile/test01.dbf /data/app/oracle/oradata/ORCL/datafile/test01.dbf.bk
    [oracle@prod ~]$ mv /data/app/oracle/oradata/ORCL/datafile/test02.dbf /data/app/oracle/oradata/ORCL/datafile/test02.dbf.bk
    利用RMAN进行介质恢复
    [oracle@prod ~]$ rman target /

    Recovery Manager: Release 12.1.0.2.0 - Production on Thu Jun 14 11:28:30 2018
    Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
    connected to target database: ORCL (DBID=1607304684)
    RMAN> restore tablespace "TEST";
    RMAN> recover tablespace "TEST";

    Starting recover at 14-JUN-18
    using channel ORA_DISK_1
    starting media recovery
    media recovery complete, elapsed time: 00:00:00
    Finished recover at 14-JUN-18

    RMAN> alter tablespace test online;

    Statement processed

    RMAN>

    实验二:expdp/impdp备份恢复表空间
    SQL> create tablespace test datafile '/data/app/oracle/oradata/ORCL/datafile/test01.dbf' size 1G ;
    Tablespace created.
    SQL> alter tablespace TEST add datafile '/data/app/oracle/oradata/ORCL/datafile/test02.dbf' size 1G;
    Tablespace altered.
    RMAN> backup tablespace "TEST" tag "test";
    RMAN> alter tablespace test offline;

    SQL>drop tablespace test;

    RMAN> restore tablespace test;

    Starting restore at 14-JUN-18
    using channel ORA_DISK_1
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of restore command at 06/14/2018 11:58:48
    RMAN-20202: Tablespace not found in the recovery catalog
    RMAN-06019: could not translate tablespace name "TEST"
    因为rman是用来在介质故障之后进行恢复的,手动进行的drop表空间不是介质故障,而且执行drop操作的时候表空间信息已经被从数据字典里删掉
    所以,只能找个地方,把整个库恢复到drop表空间之前,再用导出,导入的方法把这个表空间导入原来的库中
    SQL> create user elon identified by "elon" default tablespace test account unlock;
    User created.
    SQL> grant dba to elon;
    SQL> create table test as select * from user_objects where rownum < 10;
    SQL> insert into test select * from test;
    SQL> commit;
    逻辑备份表空间TEST
    [oracle@prod ~]$ expdp system/xxxxxx DIRECTORY=DUMP DUMPFILE=test.dmp TABLESPACES="test"
    SQL> drop tablespace test including contents and datafiles;

    进行恢复:
    SQL> create tablespace test datafile '/data/app/oracle/oradata/HBCG/datafile/test01.dbf' size 1G ;

    [oracle@prod ~]$ impdp system/oracle DIRECTORY=DUMP DUMPFILE=test.dmp
    SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';

    TABLESPACE_NAME STATUS
    ------------------------------ ---------
    TEST ONLINE

     实验三:清理OFFLINE表空间

    SQL> alter tablespace FDA online;

    SQL> select owner,table_name from dba_tables where tablespace_name='FDA';
    no rows selected
    SQL> select * from dba_segments where segment_name='FDA';
    no rows selected

    [oracle@SQL ~]$expdp system/xxxxxx DIRECTORY=DATA_DUMP DUMPFILE=fda.dmp LOGFILE=fda.log  TABLESPACES="FDA" 

    SQL> alter tablespace FDA offline;

    SQL>drop tablespace FDA including contents and datafiles;

  • 相关阅读:
    Struts2 helloWorld
    Python学习笔记基础汇总部分
    从控制台读入,典型的装饰者模式
    随机数产生方法小知识点
    Struts2基础知识
    面向对象原则之GOF是招式,九大原则才是精髓
    静态工厂方法
    单例模式singleton
    J2SE基础夯实系列之JDBC,链接数据库实例代码
    Ubuntu 12.04 下安装ssh 服务遇到的问题以及总结
  • 原文地址:https://www.cnblogs.com/elontian/p/9185284.html
Copyright © 2011-2022 走看看