1 安装环境在主机1上安装数据库软件,并建监听和实例,在主机2上安装数据库软件,并建监听,但不建实例。
2 主数据库配置2.1 设置数据库强制归档sqlplus / as sysdba SQL> ALTER DATABASE FORCE LOGGING; SQL> select force_logging from v$database; FOR --- YES 2.2 添加STANDBY日志文件SQL>alter database add standby logfile group 4 ('/oradata/dbtest/redo04.log') size 50m; SQL>alter database add standby logfile group 5 ('/oradata/dbtest/redo05.log') size 50m; SQL>alter database add standby logfile group 6 ('/oradata/dbtest/redo06.log') size 50m; SQL>alter 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 生成pfileSQL>create pfile from spfile; SQL>shutdown immediate; 2.3.2 修改pfilevi $ORACLE_HOME/dbs/initdbtest.ora 在最后添加如下内容: *.db_unique_name=dbtest1 *.fal_server='dbtest1' *.fal_client='dbtest2' *.standby_file_management=auto *.db_file_name_convert='/oradata/dbtest/','/oradata/dbtest/' *.log_file_name_convert='/oradata/dbtest/','/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='ENABLE' 2.3.3 生成spfileSQL> create spfile from pfile; File created. 2.4 修改监听配置文件
2.5 修改TNS配置文件[oracle@dg1 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /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)(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 = (PROTOCOL = IPC)(KEY = EXTPROC2)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) )
) 2.6 重启监听服务lsnrctl stop lsnrctl start 2.7 配置最大可用模式SQL> startup ORACLE instance started SQL> alter database set standby database to maximize availability; Database altered. SQL> exit 2.8 备份数据库[oracle@dg1 admin]$ rman target / RMAN> backup database plus archivelog; RMAN> backup current controlfile for standby; RMAN> exit 备份完成后会在闪回区生产备份文件
3 备数据库配置3.1 建立相应的文件目录包括dump文件目录,闪回区,数据文件目录,可以通过 show parameter dest命令查看 mkdir -p /oracle/app/oracle/admin/dbtest/adump mkdir -p /oracle/app/oracle/admin/dbtest/dpdump mkdir -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/trace mkdir -p /oracle/app/oracle/diag/rdbms/dbtest1/dbtest/cdump mkdir -p /oracle/app/oracle/flash_recovery_area mkdir -p /oradata/dbtest 3.2 从主数据库服务器上拷贝文件注意:下面命令在主数据库上执行 3.2.1 拷贝闪回区内容[oracle@dg1 admin]$ cd /oracle/app/oracle/flash_recovery_area scp -r ./* 192.168.132.4:/oracle/app/oracle/flash_recovery_area/ 3.2.2 拷贝参数文件[oracle@dg1 flash_recovery_area]$ cd $ORACLE_HOME/dbs scp ./* 192.168.132.4:/oracle/app/oracle/product/11.2.0/db_1/dbs/ 3.2.3 拷贝监听文件[oracle@dg1 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配置文件修改ip地址
3.5 重启监听服务lsnrctl stop lsnrctl start 3.6 恢复数据库[oracle@dg2 admin]$ rman target sys/funo1234@dbtest1 auxiliary / RMAN> duplicate target database for standby nofilenamecheck; RMAN> exit 3.7 修改参数文件[oracle@dg2 admin]$ sqlplus / as sysdba SQL> shutdown immediate; vi $ORACLE_HOME/dbs/initdbtest.ora 修改如下内容 *.db_unique_name=dbtest2
SQL> create spfile from pfile; 3.8 启动数据库SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database add standby logfile; SQL> alter database add standby logfile; SQL> alter database add standby logfile; SQL> alter database add standby logfile; SQL> alter database recover managed standby database using current logfile disconnect from session; 3.9 验证主库备库均执行如下命令: SQL> archive log list; 主库
备库
如果最后一行数字相同,说明配置成功 3.10 切换到只读模式SQL> alter database recover managed standby database cancel; SQL> alter database open read only; 3.11 切换到同步模式SQL> shutdown immediate; SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database recover managed standby database using current logfile disconnect from session; |