序号
IP
Db_name
db_unique_name
Oracle_sid
service_names
Hostname
1
primary
192.168.0.10
orcl
primary
primary
primary
primary
2
standby
192.168.0.11
orcl
standby
standby
standby
standby

 
primary库:
1、   打开归档:alter database archivelog;
2、   设置强制日志模式:alter database force logging;
3、   创建standby 数据库控制文件
alter database create standby controlfile as ‘c:\ standby.ctl’;
4、   pfile文件:
db_unique_name='primary'
log_archive_config='dg_config=(primary,standby)'
*.log_archive_dest_1='location=E:\oracle\product\10.2.0\db_1\database\archive valid_for=(all_logfiles,all_roles) db_unique_name=primary'
*.log_archive_dest_2='service=standby lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=standby'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
fal_server=standby
fal_client=primary
standby_file_management=auto
 
db_file_name_convert和log_file_name_convert是用来转化数据,指在线和standby日志文件的位置,如果两边的位置不一致,需要显示的指定:
db_file_name_convert='e:\oracle\orcl','C:\oracle\product\10.2.0\oradata\orcl'
log_file_name_convert='e:\oracle\orcl','C:\oracle\product\10.2.0\oradata\orcl'
5、   tnsnames.ora
STANDBY =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
 )
 
PRIMARY =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
 )
 
6、   listener.ora
SID_LIST_LISTENER =
 (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ORCL)
      (ORACLE_HOME = E:\oracle\product\10.2.0\db_1)
      (SID_NAME = PRIMARY)
    )
 )
 
LISTENER =
 (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521))
 )
7、   冷备全库
 
Standby库:
1、   创建相应的目录
2、   创建实例:oradim –new –sid standby -STARTMODE auto
3、   拷贝primary库全备的数据文件、归档日志、standby.ctl、口令文件(需改名)到相应目录
4、   生成pfile,将primary的pfile进行修改即可:
db_unique_name='standby'
log_archive_config='dg_config=(primary,standby)'
*.log_archive_dest_1='location=E:\oracle\product\10.2.0\db_1\database\archive valid_for=(all_logfiles,all_roles) db_unique_name=standby'
*.log_archive_dest_2='service=primary lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=primary'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
fal_server=primary
fal_client=standby
standby_file_management=auto
5、   tnsnames.ora
STANDBY =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
 )
 
PRIMARY =
 (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
 )
 
6、   listener.ora
SID_LIST_LISTENER =
 (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = ORCL)
      (ORACLE_HOME = E:\oracle\product\10.2.0\db_1)
      (SID_NAME = STANDBY)
    )
 )
 
LISTENER =
 (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1521))
 )
 
7、   测试tns配置并重启两端监听
8、   启动standby数据库到mount并开启redo传输:
startup mount
alter database recover managed standby database disconnect from session
 
测试:
PRIMARY库执行alter system switch logfile;
两边进行查询:Select max(sequence#) from v$archived_log;
两端一致时成功,否则查看alter日志查找原因。
 
另,实时应用命令:
alter database recover managed standby database using current logfile;