流程:
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