1、ORACLE 11G 搭建 DATAGUARD 步骤1 安装环境在主机 1 上安装数据库软件,并建监听和实例,在主机 2 上安装数据库软件,并建监听,但不建实例。主机 1 主机 2操作系统 redhat6.1 64 位 redhat6.1 64 位主机名 dg1 db2IP 192.168.132.3 192.168.132.4数据库软件版本 oracle 11.2.0.1.0 oracle 11.2.0.1.0ORACLE_BASE /oracle/app/oracle/ /oracle/app/oracle/ORACLE_HOME $ORACLE_BASE/product/11.2.0/d
2、b_1$ORACLE_BASE/product/11.2.0/db_1ORACLE_SID dbtest闪回区 4G归档 开启2 主数据库配置2.1 设置数据库强制归档sqlplus / as sysdbaSQL ALTER DATABASE FORCE LOGGING;SQL select force_logging from v$database;FOR-YES2.2 添加 STANDBY 日志文件SQLalter database add standby logfile group 4 (/oradata/dbtest/redo04.log) size 50m;SQLalter data
3、base add standby logfile group 5 (/oradata/dbtest/redo05.log) size 50m;SQLalter database add standby logfile group 6 (/oradata/dbtest/redo06.log) size 50m;SQLalter database add standby logfile group 7 (/oradata/dbtest/redo07.log) size 50m;SQL select * from v$logfile order by 1; 2.3 修改参数文件2.3.1 生成 pf
4、ileSQLcreate pfile from spfile;SQLshutdown immediate;2.3.2 修改 pfilevi $ORACLE_HOME/dbs/initdbtest.ora在最后添加如下内容:*.db_unique_name=dbtest1*.fal_server=dbtest2*.fal_client=dbtest1*.standby_file_management=auto*.db_file_name_convert=/oradata/dbtest/,/oradata/dbtest/*.log_file_name_convert=/oradata/dbtest
5、/,/oradata/dbtest/*.log_archive_config=dg_config=(dbtest1,dbtest2)*.log_archive_dest_2=service=dbtest2 LGWR SYNC AFFIRM valid_for=(online_logfiles,primary_role) db_unique_name=dbtest2*.log_archive_dest_state_2=ENABLE2.3.3 生成 spfile SQL shutdown immediateoracledbserver01 $ cd $ORACLE_HOME/dbsoracledb
6、server01 dbs$ mv spfilejkfwdb.ora spfilejkfwdb.ora.bakSQL startup nomountSQL create spfile from pfile;File created.SQL show parameter uniqSQL shutdown immediate;SQL startupSQL show parameter spfile2.4 修改监听配置文件2.5 修改 TNS 配置文件oracledg1 admin$ cat tnsnames.ora# tnsnames.ora Network Configuration File:
7、/oracle/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora# Generated by Oracle configuration tools.DBTEST =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.3)(PORT = 1521)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = dbtest1)DBTEST1 =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)
8、(HOST = 192.168.132.3)(PORT = 1521)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = dbtest1)DBTEST2 =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.4)(PORT = 1521)(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = dbtest2)EXTPROC_CONNECTION_DATA =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS
9、 = (PROTOCOL = IPC)(KEY = EXTPROC2)(CONNECT_DATA =(SID = PLSExtProc)(PRESENTATION = RO)2.6 重启监听服务lsnrctl stoplsnrctl start2.7 配置最大可用模式SQL alter database set standby database to maximize availability;Database altered.SQL exit2.8 备份数据库oracledg1 admin$ rman target /RMAN backup database plus archivelog;
10、RMAN backup current controlfile for standby;RMAN exit备份完成后会在闪回区生产备份文件3 备数据库配置3.1 建立相应的文件目录包括 dump 文件目录,闪回区,数据文件目录,可以通过 show parameter dest 命令查看mkdir -p /oracle/app/oracle/admin/dbtest/adumpmkdir -p /oracle/app/oracle/admin/dbtest/dpdumpmkdir -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/tracemkdir
11、 -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/cdumpmkdir -p /oracle/app/oracle/flash_recovery_areamkdir -p /oradata/dbtest3.2 从主数据库服务器上拷贝文件注意:下面命令在主数据库上执行3.2.1 拷贝闪回区内容oracledg1 admin$ cd /oracle/app/oracle/flash_recovery_areascp -r ./* 192.168.132.4:/oracle/app/oracle/flash_recovery_area/3.2.2 拷贝
12、参数文件oracledg1 flash_recovery_area$ cd $ORACLE_HOME/dbsscp ./* 192.168.132.4:/oracle/app/oracle/product/11.2.0/db_1/dbs/3.2.3 拷贝密码文件3.2.4 拷贝监听文件和 tns 文件oracledg1 dbs$ cd ./network/admin/scp *.ora 192.168.132.4:/oracle/app/oracle/product/11.2.0/db_1/network/admin/3.3 修改监听配置文件修改 ip 地址3.4 修改 TNS 配置文件修改
13、ip 地址3.5 重启监听服务lsnrctl stoplsnrctl start3.6 修改参数文件并启动数据库到 nomountCd $ORACLE_HOME/dbsCp initdbtest.ora initdbtest.ora.bakvi $ORACLE_HOME/dbs/initdbtest.ora去掉 上面添加的部分即:*.db_unique_name=dbtest1*.fal_server=dbtest2*.fal_client=dbtest13.7 恢复数据库oracledg2 admin$ rman target sys/funo1234dbtest1 auxiliary /R
14、MAN duplicate target database for standby nofilenamecheck;RMAN exit3.8 修改参数文件oracledg2 admin$ sqlplus / as sysdbaSQL shutdown immediate;vi $ORACLE_HOME/dbs/initdbtest.ora添加如下内容*.db_unique_name=dbtest2SQL create spfile from pfile;3.9 启动数据库SQL startup nomount;SQL alter database mount standby database;
15、SQL alter database recover managed standby database using current logfile disconnect from session; 3.10 验证主库备库均执行如下命令:SQL archive log list;主库备库如果最后一行数字相同,说明配置成功3.11 切换到只读模式SQL alter database recover managed standby database cancel;SQL alter database open read only;3.12 切换到同步模式(不需要停库)SQL alter database recover managed standby database using current logfile disconnect from session;