最近太忙,也就无暇每日检查数据库的同布情况,后来才发现主库压根没有同步归档日志到备库,因为备库断电后一直没有开,但问题是主库在10几天前删除过归档日志,惨!为了想节省时间,想去备份捞捞看,结果是备份也没有需要的归档日志。无耐,只好重建。
1、登录主库备份控制文件到数据文件所在的目录。
1.1先查询数据文件所在的目录:select name from v$datafile
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/ora/oracle/oradata/tsing/system01.dbf
/ora/oracle/oradata/tsing/undotbs01.dbf
/ora/oracle/oradata/tsing/sysaux01.dbf
/ora/oracle/oradata/tsing/users01.dbf
/ora/oracle/oradata/tsing/mast.dbf
/ora/oracle/oradata/tsing/mas.dbf
6 rows selected.
1.2 备份控制文件到数据文件所在的目录
SQL> alter database create standby controlfile as '/ora/oracle/oradata/tsing/node1.ctl';
Database altered.
2、登录备库删除数据文件
2.1关闭备库实例
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
2.2进入数据文件所在的目录,然后删除
cd /ora/oracle/oradata/tsing/
[oracle@TAIXIN-HR1 tsing]$ ls
control01.ctl mast.dbf redo03.log stdREDO04.LOG undotbs01.dbf
control02.ctl orapwtsing stdREDO01.LOG sysaux01.dbf users01.dbf
control03.ctl redo01.log stdREDO02.LOG system01.dbf
mas.dbf redo02.log stdREDO03.LOG temp01.dbf
[oracle@TAIXIN-HR1 tsing]$ rm -f *
3、从主库用SCP命令将数据文件及控制文件传到备库
scp -r /ora/oracle/oradata/tsing/* oracle@TAIXIN-HR1:/ora/oracle/oradata/tsing/
oracle@taixin-hr1's password:
control01.ctl 100% 7088KB 6.9MB/s 00:00
control02.ctl 100% 7088KB 6.9MB/s 00:00
control03.ctl 100% 7088KB 6.9MB/s 00:01
inittsing.ora 100% 1407 1.4KB/s 00:00
mas.dbf 100% 16GB 25.5MB/s 10:30
mast.dbf 100% 136MB 22.7MB/s 00:06
node1.ctl 100% 7088KB 6.9MB/s 00:00
orapwtsing 100% 1536 1.5KB/s 00:00
redo01.log 100% 50MB 25.0MB/s 00:02
redo02.log 100% 50MB 25.0MB/s 00:02
redo03.log 100% 50MB 25.0MB/s 00:02
sqlnet.log 100% 668 0.7KB/s 00:00
stdREDO01.LOG 100% 50MB 16.7MB/s 00:03
stdREDO02.LOG 100% 50MB 50.0MB/s 00:01
stdREDO03.LOG 100% 50MB 50.0MB/s 00:01
stdREDO04.LOG 100% 50MB 25.0MB/s 00:02
sysaux01.dbf 100% 490MB 18.9MB/s 00:26
system01.dbf 100% 520MB 21.7MB/s 00:24
temp01.dbf 100% 20MB 20.0MB/s 00:01
tsing1.ctl 100% 6928KB 6.8MB/s 00:01
undotbs01.dbf 100% 115MB 23.0MB/s 00:05
users01.dbf 100% 5128KB 5.0MB/s 00:00
[oracle@TAIXIN-HR tsing]$
4、重命名刚传到备库的控制文件
4.1先删除目录下原有的三个控制文件
[oracle@TAIXIN-HR1 tsing]$ ls
control01.ctl mast.dbf redo03.log stdREDO04.LOG undotbs01.dbf
control02.ctl node1.ctl sqlnet.log sysaux01.dbf users01.dbf
control03.ctl orapwtsing stdREDO01.LOG system01.dbf
inittsing.ora redo01.log stdREDO02.LOG temp01.dbf
mas.dbf redo02.log stdREDO03.LOG tsing1.ctl
[oracle@TAIXIN-HR1 tsing]$ rm contro*
[oracle@TAIXIN-HR1 tsing]$ ls
inittsing.ora orapwtsing sqlnet.log stdREDO04.LOG tsing1.ctl
mas.dbf redo01.log stdREDO01.LOG sysaux01.dbf undotbs01.dbf
mast.dbf redo02.log stdREDO02.LOG system01.dbf users01.dbf
node1.ctl redo03.log stdREDO03.LOG temp01.dbf
4.2 将node1.ctl的控制文件重命名成三个控制文件
[oracle@TAIXIN-HR1 tsing]$ mv node1.ctl control01.ctl
[oracle@TAIXIN-HR1 tsing]$ cp control01.ctl control02.ctl
[oracle@TAIXIN-HR1 tsing]$ cp control02.ctl control03.ctl
[oracle@TAIXIN-HR1 tsing]$ ls
control01.ctl mast.dbf sqlnet.log sysaux01.dbf users01.dbf
control02.ctl orapwtsing stdREDO01.LOG system01.dbf
control03.ctl redo01.log stdREDO02.LOG temp01.dbf
inittsing.ora redo02.log stdREDO03.LOG tsing1.ctl
mas.dbf redo03.log stdREDO04.LOG undotbs01.dbf
5、连接备库,并按如下操作
sqlplus / as sysdba
SQL>startup nomount
SQL>alter database mount standby database;
SQL>alter database recover managed standby database disconnect from session;
6、测试重建是否成功(主库切换日志后查看备库是否应用日志)
在主库上执行
SQL>alter system switch logfile;
在从库上
SQL>select sequence#,applied from v$archived_log;