环境:
角色 机器名 操作系统 IP 备注主库 db1 CentOS 5.11 x86_64 192.168.2.241 安装Oracle,创建数据库
备库 db2 CentOS 5.11 x86_64 192.168.2.242 只安装Oracle
准备工作:
在db1的/etc/hosts里增加
127.0.0.1 db1
192.168.2.242 db2
在db2的/etc/hosts里增加
127.0.0.1 db2
192.168.2.241 db1
目录
主库打开归档及强制归档
创建3组standby redolog
修改参数文件
修改监听文件
RMAN备份主库
复制文件至备库
恢复参数文件(db2)
修改备库参数文件(db2)
准备RMAN恢复工作(db2)
生成备库参数文件(db2)
恢复数据库(db2)
启动备库(db2)
1.主库打开归档及强制归档(db1)
检查Oracle是否开启归档
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Current log sequence 8
#可以看到Automatic archival Disabled说明未打开归档
打开归档(打开归档需要先关闭Oracle,然后将数据库启动至mount状态才能修改)
SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database archivelog; #打开归档
SQL> alter database force logging; #打开强制归档也可以在数据库open状态下打开
SQL> alter database open; #打开数据库
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 6
Next log sequence to archive 8
Current log sequence 8
2.创建多组standby redo log,最少需要多一组,standby redo log是使用Real Time Apply的必要条件
SQL> select group#,member from v$logfile;
GROUP# MEMBER
--------------------------------------------------------------------------------
3 /opt/oracle/oradata/tpy100/redo03.log
2 /opt/oracle/oradata/tpy100/redo02.log
1 /opt/oracle/oradata/tpy100/redo01.log
SQL> alter database add standby logfile ('/opt/oracle/oradata/tpy100/standby04.log') size 50m;
SQL> alter database add standby logfile ('/opt/oracle/oradata/tpy100/standby05.log') size 50m;
SQL> alter database add standby logfile ('/opt/oracle/oradata/tpy100/standby06.log') size 50m;
SQL> alter database add standby logfile ('/opt/oracle/oradata/tpy100/standby07.log') size 50m;
SQL> select group#,member from v$logfile;
GROUP# MEMBER
--------------------------------------------------------------------------------
3 /opt/oracle/oradata/tpy100/redo03.log
2 /opt/oracle/oradata/tpy100/redo02.log
1 /opt/oracle/oradata/tpy100/redo01.log
4 /opt/oracle/oradata/tpy100/standby04.log
5 /opt/oracle/oradata/tpy100/standby05.log
6 /opt/oracle/oradata/tpy100/standby06.log
7 /opt/oracle/oradata/tpy100/standby07.log
3.修改参数文件
修改参数文件前,我们先进行备份
SQL> create pfile='/tmp/tpy100.pfile' from spfile;
在修改前我们需要查看下备份的参数文件,根据具体环境更改下面语句
SQL> alter system set db_unique_name=db1 scope=spfile;
SQL> alter system set log_archive_config='dg_config=(db1,db2)' scope=both;
SQL> alter system set log_archive_dest_1= 'location=/opt/oracle/flash_recovery_area/ valid_for=(all_logfiles,all_roles) db_unique_name=db1' scope=both;
报错:
ERROR at line 1:
ORA-02097: parameter cannot be modified because specified value is invalid
ORA-16053: DB_UNIQUE_NAME db1 is not in the Data Guard Configuration