试验环境
primary server:
windows2000 server + oracle 10.0.1.0.2
ORACLE_SID:dgtest
ORACLE_HOME: D:\oracle\product\10.1.0\db_1
standby server:
windows XP pro + oracle 10.0.1.0.2
ORACLE_SID:dgtest
ORACLE_HOME: D:\oracle\product\10.1.0\db_1
配置步骤
首先,装好primary和standby上的oracle,建SID同为dgtest的库,所有设置完全相同。然后停止shutdown两台上的oracle,将primary上的所有数据文件,控制文件,redo文件和password文件都copy到standby机器的相应位置。(还可以利用热备,rman等来建立初始standby库)在我感觉在要配置完成,使用新参数文件启动standby的时候拷贝文件为好,这样,我们就拥有了两台完全一样的oracle server。
1. 在primary database上设置force logging
SQL>alter database force logging;
2. 修改primary databse的初始化参数
创建pfile SQL> create pfile='D:\oracle\product\pfdgtest.ora' from spfile;
修改参数:
#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’ -- oracle 10gR2后不需要该参数,用log_archive_d
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)
)
)
--使用TNSPING 测试一下listener
--拷贝数据库文件等
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
常见问题
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 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;
--------------------------------------------
我的试验环境:
Windows xp sp2 + oracle 10.2.0
ORACLE_SID: dgtest
ORACLE_HOME: D:\oracle\product\10.2.0\db_1
看过了《oracle高可用环境》那章,又体会到蛮多 o(∩_∩)o... 主要是一些参数了!
Validate whether received:
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME
FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#
Validate whethere new archive redo log have been applied.
SQL> select SEQUENCE#,DEST_ID,ARCHIVED,APPLIED,DELETED,
STATUS from v$archived_log order by SEQUENCE#
查询库状态:
SQL> select name,open_mode,PROTECTION_MODE,DATABASE_ROLE from v$database;
------------------------
网络收集资料
总结:备库在起来时:
1.nomount:rfs服务没有起,因此主库文件不会传到备库;mrp进程没有起,因此也不会做recover,归档不
会applied。
2.mount:rfs服务启动,主库的归档能传输到备库(可以在主库switchlogfile几次,会发现归档已经传输过去
);mrp进程没有启动,归档不applied。
3.recover managed:rfs在上一步已经启动,归档能传输到备库;且mrp进程已经起来,apply 归档日志!
http://www.oracleblog.cn/study-note/different-stage-on-dataguard-startup/
主备切换:
1、primary——>phsical standby:
先确认能否转换:
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
转换:
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT;
ALTER DATABASE MOUNT STANDBY DATABASE;
2、phsical standby——>primary:
先确认能否转换:
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
转换:
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SHUTDOWN;
STARTUP;
3、新primary:
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
ALTER SYSTEM ARCHIVE LOG CURRENT;