windows 下ORCLE 10g dataguard物理standby的配置
primary(主库):
操作系统 :windows2003 企业版
IP :192.168.3.34
数据库 :oracle 10.2 企业版
sid :orac
standby (备库):
操作系统:windows2003 企业版
IP :192.168.3.47
数据库:oracle 10.2 企业版
SID:无(只安装软件,不安装实例数据库)
要求数据库的版本一致,最好安装路径一致;
ORACLE 10G DATAGUARD 配置物理STANDBY
本文档查阅了网上诸多技术人员的文档,并配合自己在虚拟机下多次的尝试最终安装成功,为此将整个过程记录下来,以防自己忘记文档中部分内
容参考了其他技术人员的文档,在此做出说明
正式开始配置
1、设置主数据库为force logging 模式
cmd> sqlplus / nolog;
SQL> conn / as sysdba;
SQL>alter database force logging;
2、设置主数据库为归档模式
SQL> archive log list
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> archive log list
3、数据文件拷贝
数据文件的拷贝可以分为两种模式:rman 和文件的直接拷贝,由于我们的
系统可以停机,所以会采用第二种方式。注意不用拷贝RED 文件,备用机在启
动的时候会自动的创建RED 文件。
3.1、拷贝主库的数据文件到备库中
SQL> SELECT NAME FROM v$datafile;
SQL> select * from v$tempfile;
把主库的以上数据文件(D:\oracle\product\10.2.0\oradata\orac)拷贝到备库上同样目录
3.2、创建备库的控制文件
在主库上为从库创建控制文件和初始化参数文件,然后拷贝到从库D:\oracle\product\10.2.0\db_1\database目录下。
(记住这个目录,在下面备库的spfile 配置中要用到)。
SQL>ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'd:\backup\STANDBY.CTL';
SQL>create pfile from spfile;
在D:\oracle\product\10.2.0\db_1\database目录下找到pfile(initorac.ora);
修改其参数
orac.__db_cache_size=335544320
orac.__java_pool_size=4194304
orac.__large_pool_size=4194304
orac.__shared_pool_size=251658240
orac.__streams_pool_size=0
*.audit_file_dest='d:\oracle\product\10.2.0/admin/orac/adump'
*.background_dump_dest='d:\oracle\product\10.2.0/admin/orac/bdump'
*.compatible='10.2.0.1.0'
*.control_files='d:\oracle\product\10.2.0\oradata\orac\control01.ctl','d:\oracle\product\10.2.0\oradata\orac\control02.ctl','d:\oracle\product\10.2.0\oradata\orac\control03.ctl'
*.core_dump_dest='d:\oracle\product\10.2.0/admin/orac/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orac'
*.db_recovery_file_dest='d:\oracle\product\10.2.0/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME='primary'
*.FAL_CLIENT='primary'
*.FAL_SERVER='standby'
*.log_archive_config='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='location=C:\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'
*.log_archive_format='%T%S%r.ARC'
*.open_cursors=300
*.pga_aggregate_target=201326592
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=603979776
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='d:\oracle\product\10.2.0/admin/orac/udump'
然后保存,在主库上执行
SQL> shutdown immediate
SQL>startup pfile='D:\oracle\product\10.2.0\db_1\database\initorac.ora'
SQL> create spfile from pfile;
SQL> startup
3.3 在备库上创建一个Windows服务和密码文件
创建服务C:\Documents and Settings\Administrator>oradim -new -sid orac -startmode auto
创建密码文件C:\Documents and Settings\Administrator>orapwd file=D:\oracle\product\10.2.0\db_1\database\PWDorac.ora password=123456 entries=5;
3.4 备库创建admin目录
将主库的d:\oracle\product\10.2.0\admin\orac 目录及文件夹(adump,bdump,cdump,dpdump,pfile,udump)拷贝到备库的相同目录。
3.5 拷贝控制文件和参数文件
备库的控制文件(D:\backup\standby。ctl)已经创建, 只需要从主库拷贝到备库的(D:\oracle\product\10.2.0\oradata\orac)下
此时备库已经存在 数据文件和控制文件。
3.6 拷贝初始化参数文件到备库
将主库下的初始化参数文件(D:\oracle\product\10.2.0\db_1\database\initorac.ora)
拷贝到备库D:\oracle\product\10.2.0\db_1\database\initorac.ora下
4、修改备库pfile文件
修改备库的D:\oracle\product\10.2.0\db_1\database\initorac.ora文件如下
--------------------------standby.ora------------------------------------------
orac.__db_cache_size=335544320
orac.__java_pool_size=4194304
orac.__large_pool_size=4194304
orac.__shared_pool_size=251658240
orac.__streams_pool_size=0
*.audit_file_dest='d:\oracle\product\10.2.0/admin/orac/adump'
*.background_dump_dest='d:\oracle\product\10.2.0/admin/orac/bdump'
*.compatible='10.2.0.1.0'
*.control_files='d:\oracle\product\10.2.0\oradata\orac\STANDBY.CTL'
*.core_dump_dest='d:\oracle\product\10.2.0/admin/orac/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='orac'
*.db_recovery_file_dest='d:\oracle\product\10.2.0/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.DB_UNIQUE_NAME='standby'
*.FAL_CLIENT='standby'
*.FAL_SERVER='primary'
*.log_archive_config='DG_CONFIG=(primary,standby)'
*.log_archive_dest_1='location=C:\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'
*.log_archive_format='%T%S%r.ARC'
*.open_cursors=300
*.pga_aggregate_target=201326592
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=603979776
*.STANDBY_FILE_MANAGEMENT='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='d:\oracle\product\10.2.0/admin/orac/udump'
------------------------------------------------------------------------------------------
4.2、在备库上创建spfile文件
在备库上执行以下命令:
C:\Documents and Settings\Administrator>sqlplus "/@standby as sysdba";
SQL> startup pfile='D:\oracle\product\10.2.0\db_1\database\initorac.ora'
SQL> CREATE SPFILE FROM PFILE='D:\oracle\product\10.2.0\db_1\database\initorac.ora';
SQL>startup
6、配置网络,修改listener.ora ,tnsnames.ora
6.1 配置
先在主从库上分别用netca 命令配置监听和本地服务名,再分别编辑主、从库的listener.ora,
tnsnames.ora,参数以下
主库的listener.ora 文件如下:
######################################################################################################
# listener.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ORAC)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(SID_NAME = ORAC)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = acct-zhangpei)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
######################################################################################################
主库的tnsnames.ora 文件如下:
######################################################################################################
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.34)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orac)
)
)
primary =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.34)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orac)
)
)
standby =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.47)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orac)
)
)
######################################################################################################
从库的listeners.ora 如下
######################################################################################################
# listener.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ORAC)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(SID_NAME = ORAC)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = sss-f115w6wz6ge)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
######################################################################################################
从库的tnsnames.ora 文件如下:
##########################################################################################################################################################################################################
# tnsnames.ora Network Configuration File: C:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
PRIMARY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.34)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORAC)
)
)
STANDBY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.47)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORAC)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
######################################################################################################
在上面配置完成之后,需要在主、备机上重启监听服务
CMD> Lsnrctl stop
CMD> lsnrctl start
可以使用lsnrctl status 命令查看监听器状态
6.2 测试网络配置
如果配置成功,在主机上测试
SQL> conn sys/123456@standby as sysdba;
如果配置成功,在备库上测试
SQL> conn sys/123456@primary as sysdba; 也能得到相似结果
则说明网络配置成功。
7、启动主备服务
7.1 主库:
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
7.2 备库:
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
到次为止,最关键的时刻来了,我们要测试看是否配置成功,如果成功的话在主机上的归档
就能顺利传到
7.3 测试归档
1. 测试主库产生的归档日志是否能正常传送到归档日志
在主机上
SQL>archive log list;
SQL>alter system archive log current;
SQL>archive log list;
主库进行日志切换:
SQL>Alter system switch logfile;
然后分别查看主库和备库的D:\arch 目录下是否产生了同样的归档日志
文件。
select max(sequence#) from v$archived_log;
select max(sequence#) from v$log_history;
select group#,sequence#,archived,status from v$log;
select name,sequence#,applied from v$archived_log;
select sequence#,applied from v$archived_log;
若不同步,
1. 看log 日志, archive 是否有丢失
2. 可以在备库做如下操作:
alter database recover managed standby database cancel;
alter database recover managed standby database disconnect from session;
日常维护
1、正确打开主库和备库
主库:
SQL> STARTUP MOUNT;
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
备库:
SQL> STARTUP MOUNT;
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE
DISCONNECT FROM SESSION;
2、正确关闭顺序
备库:
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL>SHUTDOWN IMMEDIATE;
主库
SQL>SHUTDOWN IMMEDIATE;
3、备库Read-Only模式打开
当前主库正常OPEN 状态、备库处于日志传送状态.
1 在备库停止日志传送
SQL> recover managed standby database cancel;
2 备库Read-only 模式打开
SQL> alter database open read only;
3 备库回到日志传送模式
SQL> recover managed standby database disconnect from session;
SQL> select status from v$instance;
4、日志传送状态监控
1 主库察看当前日志状况
SQL> select sequence#,status from v$log;
2 备库察看RFS(Remote File Service)接收日志情况和MRP 应用日志同步主库
情况
SQL> SELECT PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS
FROM V$MANAGED_STANDBY;
3 察看备库是否和主库同步
SQL> SELECT ARCHIVED_THREAD#, ARCHIVED_SEQ#, APPLIED_THREAD#,
APPLIED_SEQ# FROM V$ARCHIVE_DEST_STATUS;
4 察看备库已经归档的redo
SQL> SELECT REGISTRAR, CREATOR, THREAD#, SEQUENCE#, FIRST_CHANGE#,
NEXT_CHANGE# FROM V$ARCHIVED_LOG;
5 察看备库已经应用的redo
SQL> SELECT THREAD#, SEQUENCE#, FIRST_CHANGE#, NEXT_CHANGE#
FROM V$LOG_HISTORY;
6 察看备库接收,应用redo 数据过程.
SQL> SELECT MESSAGE FROM V$DATAGUARD_STATUS;
5 备库归档目录维护
1 找到备库归档目录
SQL> show parameter log_archive_dest_1
2 维护策略
每周2,4,7 删除已经应用的归档文件
具体参见附录二
主库正常切换
一人工干预主库正常切换
1 在主库端检验数据库可切换状态
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS:TO STANDBY 表示可以正常切换.
如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE,表示当前有会话处于ACTIVE
状态
2 开始主库正常切换
如果SWITCHOVER_STATUS 的值为TO STANDBY 则:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE 则:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION
SHUTDOWN;
成功运行这个命令后,主库被修改为备库
3 重启先前的主库
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
4 在备库验证可切换状态
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY
1 row selected
5 将目标备库转换为主库
如果SWITCHOVER_STATUS 的值为TO STANDBY 则:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE 则:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
成功运行这个命令后,备库被修改为主库
6 重启目标备库
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
7 先前主库启动日志传送进程
SQL> alter database recover managed standby database disconnect;
总结: 这样主库的一次正常切换完成.切换后的状态,原先的主库变为备库,原先
的备库变为主库.
二通过运行脚本实现主库正常切换
1 主库切换为备库
在主库上运行脚本
/admin/dataGuard/switchover/primary_to_standby.sh
2 备库切换为主库
在备库上运行脚本
/admin/dataGuard/switchover/standby_to_primary.sh
脚本1 成功运行后,再运行脚本2,不能同时运行两个脚本.
经过这次切换后原来的主库变为备库,原先的备库变为主数据并且OPEN 对应用
提供服务.
3 复原最初状态
在原备库上运行脚本
/admin/dataGuard/switchover/primary_to_standby.sh
成功完成后
在原主库上运行脚本
/admin/dataGuard/switchover/standby_to_primary.sh
主库灾难切换
一人工干预主库灾难切换
二通过运行脚本实现主库灾难切换
SQL>alter database recover managed standby database cancel;
SQL>shutdown immediate
SQL>startup mount
SQL>ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE;
SQL>alter database recover managed standby database finish;
-- switch
SQL>alter database commit to switchover to primary with session shutdown;
-- open
SQL>shutdown immediate
SQL>startup