ITPub博客

首页 > 数据库 > Oracle > Backup && recover read only tablespace

Backup && recover read only tablespace

Oracle 作者:zhouxianwang 时间:2015-02-03 09:57:56 0 删除 编辑

1.alter tablesacpe  read only

    SQL> alter tablespace test1 read only;
   
    Tablespace altered.
   
    SQL> alter tablespace test2 read only;
   
    Tablespace altered.
   
    SQL> commit;
   
    Commit complete.
   

check read only tablespace: 

 SQL> select tablespace_name,status  from dba_tablespaces where status='READ ONLY';

 2.backup read only tablespace (exclude tablespace);

     backup tablespace test1 format='/u02/rmback/data/%N_%f_%s.dbf';
   
     backup tablespace test2  format='/u02/rmback/data/%N_%f_%s.dbf';
   
   
     linux cp datafile :   
   


3.configure rman   
   rman target /
  
   CONFIGURE EXCLUDE FOR TABLESPACE 'TEST1';
   CONFIGURE EXCLUDE FOR TABLESPACE 'TEST2';
  

4.rman backup  level 0;    
   nohup  /u02/rmback/scripts/rmback_level0.sh  &

 

5. delete database

 

6.restore and recover database

     RMAN> restore database; 
    
     RMAN> recover database;
    
                                          
     RMAN> restore database check readonly;
    ## RMAN>RECOVER DATABASE DELETE ARCHIVELOG;
    
    
     SQL> alter database datafile '/u02/oradata/hanmi/test1.dbf' offline;
                                                                        
     Database altered.                                                  
                                                                   
     SQL> alter database datafile 8 offline   
    
    SQL> alter database open resetlogs;    

7.restore and recover read only tablespace
     cp test1.dbf  /u02/oradata/hanmi/   
     cp test2.dbf  /u02/oradata/hanmi/ 
    
     select a.name,b.name,b.status from v$tablespace a,v$datafile b where a.ts#=b.ts# and a.name like '%TEST%';
    
     SQL> shutdown immediate;
     SQL> startup mount;
     SQL> alter database datafile 6  online;
     SQL> alter database datafile 8 online;
     SQL> alter database open;   
    
    
 8.restore and recover read only tablespace (method 2)
 
   SQL> shutdown immediate;
  SQL> startup mount;

  RMAN> restore tablespace test1;
  RMAN> restore tablespace test2; 
  SQL> alter database open; 
                                                 

check:
     SQL> select a.name,b.name,b.status from v$tablespace a,v$datafile b where a.ts#=b.ts# and a.name like '%TEST%';
    
     SQL> select tablespace_name ,status from dba_tablespaces;
    
     SQL> select name,checkpoint_change# from v$datafile_header;  

 

在使用只读表空间时,有几点需要注意:

1. 如果有事物在用户发出'alter tablespace xxx read only'前开始,且没有提交,不管这些事物是否与这个表空间有关,'alter xxx read only'会被阻塞直到那些事物提交或回滚。
--可以用以SQL找出阻塞read only的会话,必要时可kill这些会话。
SELECT S.SID, S.SERIAL#
FROM (SELECT SES_ADDR, START_SCNB, S.SADDR, MIN(START_SCNB) KEEP(DENSE_RANK FIRST ORDER BY DECODE(SADDR, NULL, 2, 1), START_SCNB) OVER() MIN_SCN
FROM V$TRANSACTION T,
(SELECT S.SADDR
FROM V$SQLAREA SQ, V$SESSION S
WHERE SQ.SQL_ID = S.SQL_ID
AND LOWER(SQL_TEXT) LIKE 'alter tablespace%') S
WHERE T.SES_ADDR = S.SADDR(+)) B, V$SESSION S
WHERE B.SADDR IS NULL
AND START_SCNB < MIN_SCN
AND B.SES_ADDR = S.SADDR;
上述SQL原理很简单,就是找出'alter tablespace read only'的SCN,并找出活动事物中,开始SCN比该SCN还要小的会话。

2. 只读表空间只需备份一次,日常数据库备份可通过skip readonly选项来跳过对只读表空间的备份。
3. 在做全库恢复时(restore database),默认是不恢复只读表空间的;如果需要restore 只读表空间,可用restore tablespace命令实现。
4. 一个好的习惯是,无论何时把表空间设为只读,要立刻备份该表空间。
5. 如果需要对只读表空间设置成read write模式,再修改数据,重新置为read only后要立刻备份该表空间,以免因为疏忽导致原来只读表空间因为时间过长,缺少归档日志而无法恢复。
6. 如果表(如分区表)的一部分数据在只读表空间中,一部分不在只读表空间中,只有在只读表空间的数据不能被修改,其余数据可以正常修改。


reference:
   http://blog.itpub.net/post/12157/509405
   http://xsb.itpub.net/post/419/456614


source:http://blog.itpub.net/7583803/viewspace-717958/


6.2.1.1 Recovery of Databases with Read-Only Tablespaces

Read-only tablespaces may require special handling in a restore and recover operation. By default, the restore operation will skip read-only tablespaces. If a read-only tablespace is at the SCN where it became read-only after it is restored from backup, no redo will be applied to it when the rest of the database is recovered. You can force RMAN to restore any missing datafiles belonging to read-only tablespaces by using the CHECK READONLY option to the RESTORE command:

RMAN> RESTORE DATABASE CHECK READONLY;
RMAN> RECOVER DATABASE DELETE ARCHIVELOG;

If RMAN completes the recovery without error, you can open the database:

RMAN> ALTER DATABASE OPEN;







来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27036311/viewspace-1424593/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2012-06-04

  • 博文量
    144
  • 访问量
    493866