安装环境:OS:RHL5+ORACLE10G10.2.0.1
IP:192.168.1.202(primary) 192.168.1.102(standby)ORACLE_SID:oradbORACLE_HOME:/u01/oracle/product/10g配置standby database为MAXIMIZE PERFORMANCE模式
1.设置主库为force logging
[oracle@primary /]$ sqlplus / as sysdbaSQL> startupSQL> alter database force logging;2.设置primary(主库)为归档模式:SQL> archive log listSQL> alter system set log_archive_dest_1='location=/opt/archivelog/arch1' scope=spfile; //设置归档路径SQL> shutdown immediateSQL> startup mountSQL> alter database archivelog;SQL> alter database open;SQL> archive log list;3.检查primary(主库)是否有口令文件,如没有需建立orapwd file='/u01/oracle/product/10g/dbs/orawdorcl.ora' password=oracledb entries=54.为主数据库添加"备用联机日志文件"SQL> alter database add standby logfile group 4 ('/u01/oracle/product/oradata/oradb/redo04.log') size 50M;Database altered.SQL> alter database add standby logfile group 5 ('/u01/oracle/product/oradata/oradb/redo05.log') size 50m;Database altered.SQL> alter database add standby logfile group 6 ('/u01/oracle/product/oradata/oradb/redo06.log') size 50M;Database altered.SQL> alter database add standby logfile group 7 ('/u01/oracle/product/oradata/oradb/redo07.log') size 50M;Database altered.5.修改primary(主库)参数文件SQL> create pfile='/u01/oracle/product/10g/dbs/initoradb.ora' from spfile;[oracle@primary /]$ vi /u01/oracle/product/10g/dbs/initoradb.oraoradb.__db_cache_size=155189248oradb.__java_pool_size=4194304oradb.__large_pool_size=4194304oradb.__shared_pool_size=62914560oradb.__streams_pool_size=0*.audit_file_dest='/u01/oracle/product/admin/oradb/adump'*.background_dump_dest='/u01/oracle/product/admin/oradb/bdump'*.compatible='10.2.0.1.0'*.control_files='/u01/oracle/product/oradata/oradb/control01.ctl','/u01/oracle/product/oradata/oradb/control02.ctl','/u01/oracle/product/oradata/oradb/control03.ctl'*.core_dump_dest='/u01/oracle/product/admin/oradb/cdump'*.db_block_size=8192*.db_domain=''*.db_file_multiblock_read_count=16*.db_name='oradb'*.db_recovery_file_dest='/u01/oracle/product/flash_recovery_area'*.db_recovery_file_dest_size=2147483648*.dispatchers='(PROTOCOL=TCP) (SERVICE=oradbXDB)'*.job_queue_processes=10*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'*.LOG_ARCHIVE_MAX_PROCESSES=30*.open_cursors=300*.pga_aggregate_target=75497472*.processes=150*.remote_login_passwordfile='EXCLUSIVE'*.sga_target=228589568*.undo_management='AUTO'*.undo_tablespace='UNDOTBS1'*.user_dump_dest='/u01/oracle/product/admin/oradb/udump'#add below parameter for primary database //添加以下配置信息
*.DB_UNIQUE_NAME='primary'*.FAL_CLIENT='primary'*.FAL_SERVER='standby'*.log_archive_config='DG_CONFIG=(primary,standby)'*.log_archive_dest_1='location=/opt/archivelog/arch1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=primary'*.log_archive_dest_2='SERVICE=standby arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby'*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'*.STANDBY_FILE_MANAGEMENT='AUTO'6.primary(主库)用PFILE建立SPFILE
[oracle@primary /]$ sqlplus '/ as sysdba'SQL> create spfile from pfile='/u01/oracle/product/10g/dbs/initoradb.ora';7.建立备用库的控制文件SQL> alter database create standby controlfile as '/u01/oracle/product/oradata/oradb/standby_ctl01.ctl';8. 配置primary(主库) listener.ora,tnsnames.ora 文件[root@primary /]# cd /u01/app/oracle/10.2.0/db_1/network/admin[root@primary admin]# vi listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = oradb) (ORACLE_HOME = /u01/oracle/product/10g) (SID_NAME = oradb) ) )LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521)) ) )[root@primary admin]# vi tnsnames.ora
PRIMARY = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oradb) ) )STANDBY = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oradb) ) )EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) )到此primary(主库)就配置完成,下面进入standby(备库)配置:
1. 安装oracle 10g 数据库软件,不创建数据库。
注:standby(备库)安装的数据库版本与目录结构与primary(主库)相同。2.拷贝 primary(主库)的密码文件,控制文件,数据文件,参数文件,日志文件到 standby(备库)[root@primary admin]# cd /u01/oracle/product/[root@primary product]# ls10g admin flash_recovery_area oradata oraInventory[root@primary product]# scp -r admin [root@primary product]# scp -r oradata [root@primary product]# scp -r flash_recovery_area [root@primary product]# scp -r admin [root@primary dbs]# cd /u01/oracle/product/10g/dbs/[root@primary product]# scp -r initoradb.ora [root@primary product]# scp -r orapworadb 3.登录 standby(备库) 进行配置:[root@standby /]# cd /u01/oracle/product/[root@standby product]# chown -R oracle:oinstall admin flash_recovery_area oradata[root@standby product]# cd oradata[root@standby oradb]# lscontrol01.ctl control03.ctl redo01.log redo03.log redo05.log redo07.log sysaux01.dbf temp01.dbf users01.dbfcontrol02.ctl example01.dbf redo02.log redo04.log redo06.log standby_ctl01.ctl system01.dbf undotbs01.dbf[root@standby oradb]# rm -rf control01.ctl [root@standby oradb]# mv standby_ctl01.ctl control01.ctl[root@standby oradb]# rm -rf control02.ctl control03.ctl [root@standby oradb]# lscontrol01.ctl redo01.log redo03.log redo05.log redo07.log system01.dbf undotbs01.dbfexample01.dbf redo02.log redo04.log redo06.log sysaux01.dbf temp01.dbf users01.dbf[root@standby oradb]# cp control01.ctl control02.ctl [root@standby oradb]# cp control01.ctl control03.ctl [root@standby oradb]# lscontrol01.ctl control03.ctl redo01.log redo03.log redo05.log redo07.log system01.dbf undotbs01.dbfcontrol02.ctl example01.dbf redo02.log redo04.log redo06.log sysaux01.dbf temp01.dbf users01.dbf[root@standby /]# cd /u01/oracle/product/10g/dbs/[root@standby dbs]# chown -R oracle:oinstall orapworadb initoradb.ora4.修改 standby(备库)参数文件[root@standby /]# cd /u01/oracle/product/10g/dbs[root@standby dbs]# vi initoradb.ora修改为如下:oradb.__db_cache_size=150994944oradb.__java_pool_size=4194304oradb.__large_pool_size=4194304oradb.__shared_pool_size=67108864oradb.__streams_pool_size=0*.audit_file_dest='/u01/oracle/product/admin/oradb/adump'*.background_dump_dest='/u01/oracle/product/admin/oradb/bdump'*.compatible='10.2.0.1.0'*.control_files='/u01/oracle/product/oradata/oradb/control01.ctl','/u01/oracle/product/oradata/oradb/control02.ctl','/u01/oracle/product/oradata/oradb/control03.ctl'*.core_dump_dest='/u01/oracle/product/admin/oradb/cdump'*.db_block_size=8192*.db_domain=''*.db_file_multiblock_read_count=16*.db_name='oradb'*.db_recovery_file_dest='/u01/oracle/product/flash_recovery_area'*.db_recovery_file_dest_size=2147483648*.dispatchers='(PROTOCOL=TCP) (SERVICE=oradbXDB)'*.job_queue_processes=10*.LOG_ARCHIVE_FORMAT='%t_%s_%r.arc'*.LOG_ARCHIVE_MAX_PROCESSES=30*.open_cursors=300*.pga_aggregate_target=75497472*.processes=150*.remote_login_passwordfile='EXCLUSIVE'*.sga_target=228589568*.undo_management='AUTO'*.undo_tablespace='UNDOTBS1'*.user_dump_dest='/u01/oracle/product/admin/oradb/udump'#add below parameter for standby database //添加以下配置信息
*.DB_UNIQUE_NAME='standby'*.log_archive_config='DG_CONFIG=(primary,standby)'*.log_archive_dest_1='location=/opt/archivelog/arch1 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=standby'*.log_archive_dest_2='SERVICE=standby arch ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'*.LOG_ARCHIVE_DEST_STATE_1='ENABLE'*.LOG_ARCHIVE_DEST_STATE_2='ENABLE'*.STANDBY_FILE_MANAGEMENT='AUTO'*.FAL_CLIENT='standby'*.FAL_SERVER='primary'5.配置standby(备库) 的listener.ora,tnsnames.ora 文件
[root@standby /]# cd /u01/oracle/product/10g/network/admin/[root@standby admin]# vi listener.oraSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = oradb) (ORACLE_HOME = /u01/oracle/product/10g) (SID_NAME = oradb) ) )LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521)) ) )[root@standby admin]# vi tnsnames.oraprimary = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.202)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oradb) ) )STANDBY = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.102)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oradb) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) )6. 测试 primary(主库)与 standby(备库)之间网络连通
[oracle@standby ~]$ lsnrctl start[oracle@standby ~]$ tnsping primary[oracle@primary ~]$ lsnrctl start[oracle@primary ~]$ tnsping standby7. 打开standby(备库)
[oracle@standby admin]$ sqlplus / as sysdbaSQL> startup mount pfile='/u01/oracle/product/10g/dbs/initoradb.ora';SQL> create spfile from pfile='/u01/oracle/product/10g/dbs/initoradb.ora';SQL> alter database recover managed standby database disconnect from session;注;Data Guard 启动顺序:standby(备库) --> primary(主库)
Data Guard 启动顺序: primary(主库) --> standby(备库)8.打开 primary(主库)
[oracle@primary /]$ sqlplus / as sysdbaSQL> startup测试 primary(主库)与 standby(备库) 归档日志文件是否同步:
primary(主库)操作:SQL> alter system switch logfile;SQL> select FIRST_TIME,NEXT_TIME, APPLIED,SEQUENCE# from v$archived_log order by SEQUENCE#;FIRST_TIM NEXT_TIME APP SEQUENCE#--------- --------- --- ----------26-OCT-11 27-OCT-11 YES 1227-OCT-11 27-OCT-11 YES 13standby(备库)操作:
SQL> select FIRST_TIME,NEXT_TIME, APPLIED,SEQUENCE# from v$archived_log order by SEQUENCE#;FIRST_TIM NEXT_TIME APP SEQUENCE#
--------- --------- --- ----------26-OCT-11 26-OCT-11 YES 1226-OCT-11 26-OCT-11 YES 13测试成功 !!!查看当前数据库的运行模式及状态:
SQL> select switchover_status,database_role,protection_mode from v$database; 备库停止归档日志应用SQL> alter database recover managed standby database cancel;SQL> shutdown immediate; 注意:数据库关机顺序。。。。。