试验环境primary server:
windows2000 server + Oracle 10.0.1.0.2
ORACLE_SID:dgtest
ORACLE_HOME: D:\oracle\prodUCt\10.1.0\db_1standby server:
windows XP pro + oracle 10.0.1.0.2ORACLE_SID:dgtestORACLE_HOME: D:\oracle\product\10.1.0\db_1
配置步骤首先,装好primary和standby上的oracle,建SID同为dgtest的库,所有设置完全相同。然后停止shutdown两台上的oracle,将primary上的所有数据文件,控制文件,redo文件和passWord文件都copy到standby机器的相应位置。(还可以利用热备,rman等来建立初始standby库),这样,我们就拥有了两台完全一样的oracle server
1. 在primary database上设置force loggingSQL>alter database force logging;
2. 修改primary databse的初始化参数DB_UNIQUE_NAME=’primary’CONTROL_FILES='d:\oracle\product\oradata\control01.ctl','d:\oracle\product\oradata\control02.ctl','d:\oracle\product\oradata\control03.ctl'LOG_ARCHIVE_DEST_1= 'LOCATION= d:\oracle\product\arch’LOG_ARCHIVE_DEST_2= 'SERVICE=standby'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLEREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVELOG_ARCHIVE_FORMAT='arc%s%t%r.arc'FAL_SERVER=standbyFAL_CLIENT=primarySTANDBY_FILE_MANAGEMENT=AUTOLOCK_NAME_SPACE ----这是当主数据库和备用数据在同一台机上时要设该参数,设为备用数据库的SID
3. 设置primary database为archivelog模式SQL>shutdown immediate;SQL>startup mount;SQL>alter database archivelog;SQL>alter database open:
4. 在primary database上创建standby database的控制文件SQL>shutdown immedaite;SQL>startup mount;SQL>alter database create standby controlfile as ‘d:\oracle\product\oradata\controlstandby.ctl’SQL>alter database open;然后将该controlfile复制到standby server的对应位置
5. 修改standby databse的初始化参数DB_UNIQUE_NAME=’standby’CONTROL_FILES='d:\oracle\product\oradata\controlstandby.ctl'LOG_ARCHIVE_DEST_1= 'LOCATION= d:\oracle\product\arch’LOG_ARCHIVE_DEST_2= 'SERVICE=primary'LOG_ARCHIVE_DEST_STATE_1=ENABLELOG_ARCHIVE_DEST_STATE_2=ENABLESTANDBY_ARCHIVE_DEST=’ d:\oracle\product\arch’
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVEFAL_SERVER=primaryFAL_CLIENT=standbySTANDBY_FILE_MANAGEMENT=AUTODB_FILE_NAME_CONVERT
----当primary和standby的数据文件路径不一致时使用LOG_FILE_NAME_CONVERT ----当primary和standby的数据文件路径不一致时使用LOCK_NAME_SPACE ----当主数据库和备用数据在同一台机上时设为备用数据库的SID
具体参数的说明请参考oracle在线文档
6. 设置primary database和standby database的tnsnames.oraprimary = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = primary_server)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dgtest) ) )standby = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = dgtest) ) )
7. 启动standby database SQL>startup nomount pfile=’d:\oracle\product\initdgtest.ora’SQL>alter database mount standby database;
8. 启动primary databaseSQL>startup pfile=’d:\oracle\product\initdgtest.ora’
9. 启动standby database到recover manage模式SQL>alter database recover managed standby database disconnect from session;
Switchover
在primary上
1. SQL>select switchover_status from v$database switchover_status的值入股是To standby,可以直接switchover,假如是sessions active, 则需要在switchover的命令后面加上with session shutdown
2. SQL>alter database commit to switchover to physical standby;
3. SQL>shutdowm immediate;
4. SQL>startup mount;
在standby上
1. SQL> select switchover_status from v$database
switchover_status的值入股是To primary,可以直接switchover,假如是sessions active, 则需要在switchover的命令后面加上with session shutdown
2. SQL>alter database commit to switchover to primary;
3. SQL>shutdown immediate;
4. SQL>startup;
要想顺利的实现switchover,最好在每台server上都同时设置好primary和standby的一些初始化参数,虽然其中一些参数只有在primary或者standby其中之一上起作用
Failover
在standby上
1. SQL>alter database recover managed standby database finish;
or SQL>alter database recover managed standby database finish skip standby logfile;
2. SQL>alter database commit to switchover to primary;
3. SQL>shutdown immediate;
4. SQL>startup;
相关视图
v$archive_dest
v$archive_dest_status v$log_history v$archvied_log v$managed_standby v$archive_gap
常见问题
1. 日志无法传送 SQL>select dest_name,status,error from v$archive_dest; 察看相应的归档路径的状态是否valid,否则根据error信息进行处理
2. 无法使用alter database重命名data file在standby上,当设置standby_file_management为auto时,不答应下列操作alter database renamealter database add/drop logfilealter database add/drop standby logfile memberalter database create datafile as
3. switchover失败SQL>alter database commit to switchover to physical standbyORA-01093:alter database close only permitted with no session connected察看引起该错误的活动sessionSQL> select sid,process,program from v$session where type='USER' and sid<>(select distinct sid from v$mystat);断开该session,或者使用如下命令来做switchoverSQL>lter database commit to switchover to physical standby with session shutdown;