分类: Oracle
2008-09-23 23:38:55
试验环境
primary server:
windows2000 server + oracle
ORACLE_SID:dgtest
ORACLE_HOME: D:\oracle\product\
standby server:
windows XP pro + oracle
ORACLE_SID:dgtest
ORACLE_HOME: D:\oracle\product\
配置步骤
首先,装好primary和standby上的oracle,建SID同为dgtest的库,所有设置完全相同。然后停止shutdown两台上的oracle,将primary上的所有数据文件,控制文件,redo文件和password文件都copy到standby机器的相应位置。(还可以利用热备,rman等来建立初始standby库),这样,我们就拥有了两台完全一样的oracle server
1. 在primary database上设置force logging
SQL>alter database force logging;
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=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT='arc%s%t%r.arc'
FAL_SERVER=standby
FAL_CLIENT=primary
STANDBY_FILE_MANAGEMENT=AUTO
LOCK_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=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
STANDBY_ARCHIVE_DEST=’ d:\oracle\product\arch’
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
FAL_SERVER=primary
FAL_CLIENT=standby
STANDBY_FILE_MANAGEMENT=AUTO
DB_FILE_NAME_CONVERT ----当primary和standby的数据文件路径不一致时使用
LOG_FILE_NAME_CONVERT ----当primary和standby的数据文件路径不一致时使用
LOCK_NAME_SPACE ----当主数据库和备用数据在同一台机上时设为备用数据库的SID
具体参数的说明请参考oracle在线文档
6. 设置primary database和standby database的tnsnames.ora
primary =
(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 database
SQL>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
常见问题
SQL>select dest_name,status,error from v$archive_dest;
察看相应的归档路径的状态是否valid,否则根据error信息进行处理
2. 无法使用alter database重命名data file
在standby上,当设置standby_file_management为auto时,不允许下列操作
alter database rename
alter database add/drop logfile
alter database add/drop standby logfile member
alter database create datafile as
失败
SQL>alter database commit to switchover to physical standby
ORA-01093:alter database close only permitted with no session connected
察看引起该错误的活动session
SQL> select sid,process,program from v$session where type='USER' and
sid<>(select distinct sid from v$mystat);
断开该session,或者使用如下命令来做switchover
SQL>lter database commit to switchover to physical standby with session shutdown;