配置Oracle 11g Active Dataguard

一直以来都没有正儿八经的记录oracle 11g dataguard物理备库的创建步骤,11g的logical standby还没有去测试,不过个人认为随着11g adg特性的推出,logical standby其实已经没有什么吸引力了!本文介绍了11g active dataguard的详细配置步骤和数据保护模式的修改!

一:环境介绍
主库
IP地址:192.168.1.61/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg1


备库1  物理备库 (只安装oracle数据库软件,无需建库)
IP地址:192.168.1.62/24
操作系统版本:rhel5.4 64bit
数据库版本:11.2.0.3 64bit
数据库sid名:dg
数据库名:dg
数据库db_unique_name:dg2

二:修改主备库listener.ora,tnsnames.ora文件如下,备库根据自身情况修改

 
 
  1. [oracle@dg1 ~]$ cat $TNS_ADMIN/listener.ora  
  2. SID_LIST_LISTENER =  
  3.   (SID_LIST =  
  4.     (SID_DESC =  
  5.       (GLOBAL_DBNAME = dg1.yang.com)  
  6.       (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db1)  
  7.       (SID_NAME = dg)  
  8.     )  
  9.   )  
  10.  
  11. LISTENER =  
  12.   (DESCRIPTION_LIST =  
  13.     (DESCRIPTION =  
  14.       (ADDRESS_LIST =  
  15.         (ADDRESS = (PROTOCOL = TCP)(HOST = dg1.yang.com)(PORT = 1521))  
  16.       )  
  17.     )  
  18.   )  
  19.  
  20. [oracle@dg1 ~]$ cat $TNS_ADMIN/tnsnames.ora  
  21. dg1 =  
  22.   (DESCRIPTION =  
  23.     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))  
  24.     (CONNECT_DATA =  
  25.       (SERVER = DEDICATED)  
  26.       (SERVICE_NAME = dg1.yang.com)  
  27.     )  
  28.   )  
  29.  
  30. dg2 =  
  31.   (DESCRIPTION =  
  32.     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.62)(PORT = 1521))  
  33.     (CONNECT_DATA =  
  34.       (SERVER = DEDICATED)  
  35.       (SERVICE_NAME = dg2.yang.com)  
  36.     )  
  37.   )  
  38.  
  39. for_db =   
  40.  (DESCRIPTION =  
  41.     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.61)(PORT = 1521))  
  42.   ) 

三:在主库上修改dataguard配置相关的各个参数,各参数的具体含义可以参考oracle在线文档

 
 
  1. SQL> alter database force logging;  
  2. Database altered.  
  3.  
  4. SQL> alter system set db_unique_name='dg1' scope=spfile;  
  5. System altered.  
  6.  
  7. SQL> alter system set log_archive_config='DG_CONFIG=(dg1,dg2)';  
  8. System altered.  
  9.  
  10. SQL> alter system set log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=  
  11.  
  12. (all_logfiles,primary_role) db_unique_name=dg1scope=spfile;  
  13. System altered.  
  14.  
  15. SQL> alter system set log_archive_dest_2='SERVICE=dg2 lgwr sync valid_for=(online_logfile,primary_role)   
  16.  
  17. db_unique_name=dg2';  
  18. System altered.  
  19.  
  20. SQL> alter system set log_archive_dest_3='LOCATION=/u01/app/oracle/standbylog valid_for=  
  21.  
  22. (standby_logfile,standby_role) db_unique_name=dg1scope=spfile;  
  23. System altered.  
  24.  
  25. SQL> alter system set fal_client='dg1';  
  26. System altered.  
  27.  
  28. SQL> alter system set fal_server='dg2';  
  29. System altered.  
  30.  
  31. SQL> alter system set standby_file_management=auto;  
  32. System altered.  
  33.  
  34. SQL> alter database add standby logfile group 4 '/u01/app/oracle/oradata/dg/standby04.log' size 50M;  
  35. Database altered.  
  36.  
  37. SQL> alter database add standby logfile group 5 '/u01/app/oracle/oradata/dg/standby05.log' size 50M;  
  38. Database altered.  
  39.  
  40. SQL> alter database add standby logfile group 6 '/u01/app/oracle/oradata/dg/standby06.log' size 50M;  
  41. Database altered.  
  42.  
  43. SQL> alter database add standby logfile group 7 '/u01/app/oracle/oradata/dg/standby07.log' size 50M;  
  44. Database altered.  
  45.  
  46. SQL> shutdown immediate  
  47. Database closed.  
  48. Database dismounted.  
  49. ORACLE instance shut down.  
  50.  
  51. SQL> startup  
  52. ORACLE instance started.  
  53.  
  54. Total System Global Area  417546240 bytes  
  55. Fixed Size                  2228944 bytes  
  56. Variable Size             285216048 bytes  
  57. Database Buffers          121634816 bytes  
  58. Redo Buffers                8466432 bytes  
  59. Database mounted.  
  60. Database opened.  
  61.  
  62. SQL> alter system set local_listener='for_db';  
  63. System altered.  
  64.  
  65. SQL> create pfile='/home/oracle/initdg.ora' from spfile;  
  66. File created. 

三:将生成的pfile文件修改后传递到备库,注意红色字体部分

[oracle@dg1 ~]$ cat /home/oracle/initdg.ora 
dg.__db_cache_size=121634816
dg.__java_pool_size=4194304
dg.__large_pool_size=4194304
dg.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
dg.__pga_aggregate_target=167772160
dg.__sga_target=251658240
dg.__shared_io_pool_size=0
dg.__shared_pool_size=109051904
dg.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/dg/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/dg/control01.ctl','/u01/app/oracle/fast_recovery_area/dg/control02.ct
l'
*.db_block_size=8192
*.db_domain='yang.com'
*.db_name='dg'
*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4322230272
*.db_unique_name='dg2'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dgXDB)'
*.fal_client='dg2'
*.fal_server='dg1'
*.local_listener='for_db'
*.log_archive_config='DG_CONFIG=(dg1,dg2)'
*.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog valid_for=(all_logfiles,primary_role)db_unique_name=dg2'
*.log_archive_dest_2='SERVICE=dg1 lgwr sync valid_for=(online_logfile,primary_role) db_unique_name=dg1'
*.log_archive_dest_3='LOCATION=/u01/app/oracle/standbylog valid_for=(standby_logfile,standby_role)
db_unique_name=dg2'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=419430400
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'

[oracle@dg1 ~]$ scp initdg.ora 192.168.1.62:/home/oracle/

四:将备库启动到nomount状态,然后连接主库进行duplicate操作

 
 
  1. [oracle@dg2 ~]$ lsnrctl start  
  2. [oracle@dg2 ~]$ orapwd file=$ORACLE_HOME/dbs/orapwdg password=123456 entries=5 
  3. [oracle@dg2 ~]$ sqlplus /nolog  
  4. SQL*Plus: Release 11.2.0.3.0 Production on Sun Apr 22 13:36:53 2012  
  5. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  6.  
  7. SQL> conn /as sysdba  
  8. Connected to an idle instance.  
  9. SQL> create spfile from pfile='/home/oracle/initdg.ora';  
  10. File created.  
  11.  
  12. SQL> startup nomount  
  13. ORACLE instance started.  
  14.  
  15. Total System Global Area  417546240 bytes  
  16. Fixed Size                  2228944 bytes  
  17. Variable Size             285216048 bytes  
  18. Database Buffers          121634816 bytes  
  19. Redo Buffers                8466432 bytes 

[oracle@dg2 ~]$ rman target sys/123456@dg1 auxiliary sys/123456@dg2
Recovery Manager: Release 11.2.0.3.0 - Production on Sun Apr 22 13:38:33 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: DG (DBID=1694605607)
connected to auxiliary database: DG (not mounted)

RMAN> duplicate target database for standby nofilenamecheck from active database;

Starting Duplicate Db at 2012-04-22-13:39:25
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=134 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/11.2.0/db1/dbs/orapwdg' auxiliary format 
 '/u01/app/oracle/product/11.2.0/db1/dbs/orapwdg'   ;
}
executing Memory Script

Starting backup at 2012-04-22-13:39:26
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
Finished backup at 2012-04-22-13:39:28

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format 

'/u01/app/oracle/oradata/dg/control01.ctl';
   restore clone controlfile to  '/u01/app/oracle/fast_recovery_area/dg/control02.ctl' from 
 '/u01/app/oracle/oradata/dg/control01.ctl';
}
executing Memory Script

Starting backup at 2012-04-22-13:39:29
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/product/11.2.0/db1/dbs/snapcf_dg.f tag=TAG20120422T133929 RECID=1

STAMP=781277970
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 2012-04-22-13:39:32

Starting restore at 2012-04-22-13:39:32
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 2012-04-22-13:39:34

contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:
{
   set newname for tempfile  1 to 
 "/u01/app/oracle/oradata/dg/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/dg/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/dg/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/dg/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/dg/users01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format 
 "/u01/app/oracle/oradata/dg/system01.dbf"   datafile 
 2 auxiliary format 
 "/u01/app/oracle/oradata/dg/sysaux01.dbf"   datafile 
 3 auxiliary format 
 "/u01/app/oracle/oradata/dg/undotbs01.dbf"   datafile 
 4 auxiliary format 
 "/u01/app/oracle/oradata/dg/users01.dbf"   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/dg/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 2012-04-22-13:39:42
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/dg/system01.dbf
output file name=/u01/app/oracle/oradata/dg/system01.dbf tag=TAG20120422T133943
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:03:06
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/dg/sysaux01.dbf
output file name=/u01/app/oracle/oradata/dg/sysaux01.dbf tag=TAG20120422T133943
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/dg/undotbs01.dbf
output file name=/u01/app/oracle/oradata/dg/undotbs01.dbf tag=TAG20120422T133943
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/dg/users01.dbf
output file name=/u01/app/oracle/oradata/dg/users01.dbf tag=TAG20120422T133943
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 2012-04-22-13:45:05

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=781278308 file name=/u01/app/oracle/oradata/dg/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=781278308 file name=/u01/app/oracle/oradata/dg/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=781278308 file name=/u01/app/oracle/oradata/dg/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=781278308 file name=/u01/app/oracle/oradata/dg/users01.dbf
Finished Duplicate Db at 2012-04-22-13:45:29

RMAN> exit
Recovery Manager complete.

五:将备库置于active dataguard模式下

 
 
  1. [oracle@dg2 ~]$ sqlplus /nolog  
  2. SQL*Plus: Release 11.2.0.3.0 Production on Sun Apr 22 13:47:17 2012  
  3. Copyright (c) 1982, 2011, Oracle.  All rights reserved.  
  4.  
  5. SQL> conn /as sysdba  
  6. Connected.  
  7. SQL> select open_mode,database_role,db_unique_name from v$database;  
  8.  
  9. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME  
  10. -------------------- ---------------- ------------------------------  
  11. MOUNTED              PHYSICAL STANDBY dg2  
  12.  
  13. SQL> alter database open;  
  14. Database altered.  
  15.  
  16. SQL> alter database recover managed standby database using current logfile disconnect from session;  
  17. Database altered.  
  18.  
  19. SQL> select open_mode,database_role,db_unique_name from v$database;  
  20.  
  21. OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME  
  22. -------------------- ---------------- ------------------------------  
  23. READ ONLY WITH APPLY PHYSICAL STANDBY dg2  
  24.  
  25. SQL> select status from v$standby_log;  
  26.  
  27. STATUS  
  28. ----------  
  29. ACTIVE  
  30. UNASSIGNED  
  31. UNASSIGNED  
  32. UNASSIGNED  
  33.  
  34. SQL> select member from v$logfile;  
  35.  
  36. MEMBER  
  37. --------------------------------------------------------------------------------  
  38. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_3_7s76qbhq_.log  
  39. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_2_7s76q94s_.log  
  40. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_1_7s76q5w1_.log  
  41. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_4_7s76qdpk_.log  
  42. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_5_7s76qhmy_.log  
  43. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_6_7s76qlhz_.log  
  44. /u01/app/oracle/fast_recovery_area/DG2/onlinelog/o1_mf_7_7s76qp99_.log  
  45. 7 rows selected. 

六:修改dataguard的数据保护模式为最高可用性模式,根据oracle文档的解释,最高可用性数据保护模式需要先满足以下几个条件

 

 
 
  1. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  2.  
  3. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  4. ------------------------------ -------------------- --------------------  
  5. dg2                            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  
  6.  
  7.  
  8.  
  9. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  10.  
  11. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  12. ------------------------------ -------------------- --------------------  
  13. dg1                            MAXIMUM PERFORMANCE  MAXIMUM PERFORMANCE  
  14.  
  15.  
  16. SQL> alter database set standby database to maximize availability;  
  17. Database altered.  
  18.  
  19. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  20.  
  21. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  22. ------------------------------ -------------------- --------------------  
  23. dg1                            MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY  
  24.  
  25.  
  26. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  27.  
  28. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  29. ------------------------------ -------------------- --------------------  
  30. dg2                            MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY  
  31.  
  32.  
  33. 将备库shutdown后,主库的PROTECTION_LEVEL将变为RESYNCHRONIZATION  
  34. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  35.  
  36. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  37. ------------------------------ -------------------- --------------------  
  38. dg2                            MAXIMUM AVAILABILITY MAXIMUM AVAILABILITY  
  39.  
  40. SQL> alter database recover managed standby database cancel;  
  41. Database altered.  
  42.  
  43. SQL> shutdown immediate  
  44. Database closed.  
  45. Database dismounted.  
  46. ORACLE instance shut down.  
  47.  
  48. SQL> select db_unique_name,protection_mode,protection_level from v$database;  
  49.  
  50. DB_UNIQUE_NAME                 PROTECTION_MODE      PROTECTION_LEVEL  
  51. ------------------------------ -------------------- --------------------  
  52. dg1                            MAXIMUM AVAILABILITY RESYNCHRONIZATION 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值