利用Physical standby的数据文件来恢复primary上的数据损坏

                                                                                                               
流程:                                                                                                         
1.创建测试数据                                                                                                 
2.删除primary上的users表空间数据文件                                                                           
3.复制standby上的数据文件到primary                                                                             
4.recover并online表空间users                                                                                   
                                                                                                               
1.创建测试数据                                                                                                 
primary:                                                                                                       
SQL> create table scott.emptt as select * from scott.emp;                                                      
                                                                                                               
Table created.                                                                                                 
                                                                                                               
2.删除primary上的users表空间数据文件                                                                           
删除数据文件:                                                                                                 
[oracle@node1 dgtest]$ ls                                                                                      
control01.ctl control03.ctl redo01.log redo03.log    system01.dbf undotbs01.dbf                                
control02.ctl example01.dbf redo02.log sysaux01.dbf temp01.dbf    users01.dbf                                  
[oracle@node1 dgtest]$ rm users01.dbf                                                                          
[oracle@node1 dgtest]$ ls                                                                                      
control01.ctl control03.ctl redo01.log redo03.log    system01.dbf undotbs01.dbf                                
control02.ctl example01.dbf redo02.log sysaux01.dbf temp01.dbf                                                 
                                                                                                               
删除之后,因为数据库进程还能找到该文件的指针(关于原理,请参考文件系统一类的文档),                             
所以暂时所有对users表空间上的操作还不受影响                                                                    
(所以:误删除数据文件之后马上把数据文件上的数据select 还是可行的(unix),windows环境正在使用的文件根本就不能删除)
                                                                                                               
为了试验,让问题表现出来:                                                                                     
SQL> alter tablespace users offline;                                                                           
                                                                                                               
Tablespace altered.                                                                                            
                                                                                                               
SQL> alter tablespace users online;                                                                            
alter tablespace users online                                                                                  
*                                                                                                              
ERROR at line 1:                                                                                               
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file                                              
ORA-01110: data file 4: '/u01/oradata/dgtest/users01.dbf'                                                      
                                                                                                               
3.复制standby上的数据文件到primary                                                                             
3.1 停掉Redo Apply                                                                                             
SQL> alter database recover managed standby database cancel;                                                   
                                                                                                               
Database altered.                                                                                              
                                                                                                               
3.2 scp复制                                                                                                    
[oracle@node2 dgtest]$ scp users01.dbf 10.0.0.1:/u01/oradata/dgtest/                                           
                                                                                                               
3.3 start redo apply                                                                                           
SQL> alter database recover managed standby database disconnect from session;                                  
                                                                                                               
Database altered.                                                                                              
                                                                                                               
                                                                                                               
4.recover并online表空间users                                                                                   
                                                                                                               
在primary上:                                                                                                  
SQL> alter tablespace users online;                                                                            
alter tablespace users online                                                                                  
*                                                                                                              
ERROR at line 1:                                                                                               
ORA-01113: file 4 needs media recovery                                                                         
ORA-01110: data file 4: '/u01/oradata/dgtest/users01.dbf'                                                      
                                                                                                               
                                                                                                               
SQL> recover tablespace users;                                                                                 
Media recovery complete.                                                                                       
SQL> alter tablespace users online;                                                                            
                                                                                                               
Tablespace altered.                                                                                            
                                                                                                               
SQL> select count(*) from scott.emptt;                                                                         
                                                                                                               
COUNT(*)                                                                                                       
----------                                                                                                     
        14                                                                                                     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值