7.主库创建standby控制文件,我们这边利用scp传送全部文件
查看下控制文件的路径
(db1)SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/opt/oracle/oradata/member/control01.ctl
/opt/oracle/flash_recovery_area/member/control02.ctl
(db1)SQL> shutdown immediate;
(db1)SQL> startup mount;
(db1)SQL> alter database create standby controlfile as '/opt/oracle/oradata/member/standby.ctl';
#在/opt/oracle/oradata/member/目录下创建standby.ctl备机控制文件
8.复制主库数据文件和日志文件到备库
[oracle@db1 ~]$ scp -r /opt/oracle/flash_recovery_area/ /opt/oracle/admin/ /opt/oracle/diag/ /opt/oracle/oradata/ db2:/opt/oracle
9.初始化备库
在备机上使用standby的控制文件覆盖原有的控制文件,覆盖的路径可以通过上一步查找控制文件的路径了解到
[oracle@db2 ~]$ cp /opt/oracle/oradata/member/standby.ctl /opt/oracle/oradata/member/control01.ctl
[oracle@db2 ~]$ cp /opt/oracle/oradata/member/standby.ctl /opt/oracle/flash_recovery_area/member/control02.ctl
使用db2.pfile之前修改过的参数文件进行db2
(db2)SQL> startup pfile='/home/oracle/db2.pfile' nomount;
(db2)SQL> create spfile from pfile='/home/oracle/db2.pfile';
(db2)SQL> shutdown immediate;
(db2)SQL> startup nomount;
(db2)SQL> alter database mount standby database;
(db2)SQL> alter database open read only;
以下3种应用日志的方法:(a和b选一)
a.开启实时应用日志,这样在主库插入立马就可以在备机上查找到
(db2)SQL> alter database recover managed standby database using current logfile disconnect from session;
b.开启redolog应用日志,时间较长才能查询到
(db2)SQL> alter database recover managed standby database disconnect from session;
c.停止应用redolog,只接受日志,不重做
(db2)SQL> alter database recover managed standby database cancel;
至此,DataGuard搭建成功,在db1上创建表并插入数据,然后在db2上进行查询就可以查到了。一开始做的时候总是查不到数据,最后发现是上面应用日志的方法问题。
10.Dataguard测试:
查看Standby管理进程
(db1)SQL> select process from v$managed_standby;
PROCESS
---------
ARCH
ARCH
ARCH
ARCH
LNS
(db2)SQL> select process from v$managed_standby;
PROCESS
---------
ARCH
ARCH
ARCH
ARCH
RFS
RFS
RFS
RFS
MRP0
以上需要看到在主机上需要有LNS进程,在备机上需要RFS进程用来接收redo日志,MRP0进程就是负责将日志写入数据库中
在db1上进行切换日志,然后在db2上查看日志是否正常
(db1)SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
11
(db2)SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
11
(db1)SQL> alter system switch logfile;
(db1)SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
12
(db2)SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
12
从上面可以看出日志切换成功,DataGuard正常运行
11.主备切换测试:
db1---primary/db2---standby ===》db2--primary/db1--standby
[oracle@db1 ~]$ lsnrctl stop
(db1)SQL> alter database commit to switchover to physical standby with session shutdown;
(db1)SQL> shutdown immediate;
(db1)SQL> startup mount;
(db1)SQL> alter database recover managed standby database using current logfile disconnect from session;
(db1)SQL> alter database open;
[oracle@db1 ~]$ lsnrctl start
(db2)SQL> alter database commit to switchover to primary;
(db2)SQL> shutdown immediate;
(db2)SQL> startup;
以上就是主备切换的流程。
基于同一主机配置 Oracle 11g Data Guard
Oracle Data Guard (RAC+DG) 归档删除策略及脚本
Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 处理方法