ora11_node_dg(1)DG搭建过程



  1. Oracle 11g Active DataGuard 搭建配置过程

  2. 一、环境介绍:

  3.   我在 ora11-node1 和 ora11-node2 两台Linux虚拟机上首先分别安装了一套数据库软件,
  4.   在 ora11-node1 主机上创建了名为zzdb的数据库。

  5. ora11-node1 10.0.0.31
  6. ora11-node2 10.0.0.32

  7. [oracle@ora11-node2 ~]$ uname -a
    Linux ora11-node2 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  8. [oracle@ora11-node2 ~]$ cat /etc/redhat-release 
    CentOS release 6.7 (Final)


  9. 二、11g ADG部署:


  10. 1、primary端配置监听

  11. cat > $ORACLE_HOME/network/admin/listener.ora << EOF
  12. # listener.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/listener.ora
  13. # Generated by Oracle configuration tools.
  14. SID_LIST_LISTENER =
  15.   (SID_LIST =
  16.     (SID_DESC =
  17.       (SID_NAME = PLSExtProc)
  18.       (ORACLE_HOME = /oracle/product/11.2.0/db_1)
  19.       (PROGRAM = extproc)
  20.     )
  21.      (SID_DESC =
  22.        (GLOBAL_DBNAME = zzdb)
  23.        (SID_NAME = zzdb )
  24.        (ORACLE_HOME = /oracle/product/11.2.0/db_1 )
  25.     )
  26.    )

  27. ADR_BASE_LISTENER = /oracle/product
  28.      
  29. EOF

  30. cat > $ORACLE_HOME/network/admin/tnsnames.ora <<EOF
  31. # tnsnames.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
  32. # Generated by Oracle configuration tools.
  33.   
  34. zzdb_dg =
  35.   (DESCRIPTION =
  36.     (ADDRESS_LIST =
  37.       (ADDRESS = (PROTOCOL = TCP)(HOST = ora11-node2)(PORT = 1521))
  38.     )
  39.     (CONNECT_DATA =
  40.       (SERVICE_NAME = zzdb_dg)
  41.     )
  42.   )
  43.   
  44. zzdb =
  45.   (DESCRIPTION =
  46.     (ADDRESS_LIST =
  47.       (ADDRESS = (PROTOCOL = TCP)(HOST = ora11-node1)(PORT = 1521))
  48.     )
  49.     (CONNECT_DATA =
  50.       (SERVICE_NAME = zzdb)
  51.     )
  52.   )
  53.   
  54. EOF


  55. 2、修改primary端初始化参数文件
  56.  
  57. startup mount;
  58. alter system set log_archive_dest_1 = 'LOCATION=/oracle/archive' scope=both;
  59. alter database force logging;
  60. alter database open;
  61. alter system set log_archive_config = 'DG_CONFIG=(zzdb,zzdb_dg)' scope=both;
  62. alter system set log_archive_dest_1 = 'LOCATION=/oracle/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=zzdb' scope=both;
  63. alter system set log_archive_dest_2 = 'SERVICE=zzdb_dg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=zzdb_dg' scope=both;
  64. alter system set log_archive_dest_state_1 = enable;
  65. alter system set log_archive_dest_state_2 = enable;
  66. alter system set fal_server=zzdb_dg scope=both;
  67. alter system set fal_client=zzdb scope=both;
  68. alter system set standby_file_management=AUTO scope=both;
  69. alter system set db_file_name_convert='/oracle/product/oradata/zzdb','/oracle/product/oradata/zzdb' scope=spfile;
  70. alter system set log_file_name_convert='/oracle/product/oradata/zzdb','/oracle/product/oradata/zzdb' scope=spfile;


  71. 3、在primary端pfile参数文件和密码文件,并且拷贝到standby段相应位置

  72. SQL> create pfile from spfile;
  73.   
  74. File created.

  75. [oracle@ora11-node1 oracle]$ cd $ORACLE_HOME/dbs
  76.     
  77. [oracle@ora11-node1 dbs]$ scp initzzdb.ora orapwzzdb ora11-node2:$ORACLE_HOME/dbs
  78.  
  79. cd $ORACLE_BASE
  80. [oracle@ora11-node1 product]$ scp -r admin/ diag/ ora11-node2:$ORACLE_BASE



  81. 4、修改standby端的监听文件及初始化参数文件
  82.   
  83. --启动监听
  84. [oracle@ora11-node2 dbs]$ lsnrctl start


  85. --修改参数文件
  86. [oracle@ora11-node2 ~]$ sqlplus / as sysdba
  87. SQL> startup nomount;
  88. SQL> create spfile from pfile='$ORACLE_HOME/dbs/initzzdb.ora';
  89. SQL> shutdown abort;
  90. SQL> startup nomount;
  91. SQL>
  92. alter system set db_unique_name=zzdb_dg scope=spfile;
  93. alter system set log_archive_config='DG_CONFIG=(zzdb,zzdb_dg)' scope=both;
  94. alter system set log_archive_dest_1 = 'LOCATION=/oracle/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=zzdb_dg' scope=spfile;
  95. alter system set log_archive_dest_2 = 'SERVICE=zzdb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=zzdb' scope=spfile;
  96. alter system set fal_server=zzdb scope=spfile;
  97. alter system set fal_client=zzdb_dg scope=spfile;

  98. SQL> shutdown abort;
  99. SQL> startup nomount;


  100. 5、在primary端通过Rman创建备库,在 ora11-node1 上执行如下命令

  101. #primary备份数据库
  102. mkdir -p /oracle/db_backup
  103. rman target / <<!
  104. run {
  105.   CONFIGURE DEVICE TYPE DISK PARALLELISM 3;
  106.   backup database format '/oracle/db_backup/%d_%s_%p_%t.%T';
  107. }
  108. !

  109. # primary生成备库控制文件
  110. rman target / <<!
  111. run {
  112.   allocate channel c1 device type disk format '/oracle/db_backup/CON_%U';
  113.   backup current controlfile for standby;
  114. }
  115. !

  116. # cp备份文件和控制文件到standby
  117. cd /oracle/db_backup
  118. [oracle@ora11-node1 db_backup]$ scp * ora11-node2:/oracle/db_backup


  119. #standby节点,创建目录

  120. mkdir -p /oracle/db_backup
  121. mkdir -p /oracle/product/oradata/zzdb

  122. [oracle@ora11-node2 db_backup]$ ll /oracle/db_backup
  123. 总用量 1213996
  124. -rw-r----- 1 oracle oinstall 9797632 12月 29 10:23 CON_03qq19bv_1_1
  125. -rw-r----- 1 oracle oinstall 1223499776 12月 29 10:24 ZZDB_1_1_899720408.20151229
  126. -rw-r----- 1 oracle oinstall 9830400 12月 29 10:24 ZZDB_2_1_899720556.20151229
  127. [oracle@ora11-node2 db_backup]$

  128. #standby节点,恢复控制文件
  129. rman target / <<!
  130. run {
  131.   restore controlfile from '/oracle/db_backup/CON_03qq19bv_1_1';
  132.   alter database mount;
  133. }
  134. !

  135. #standby节点,通过rman进行恢复
  136. rman target / <<!
  137.  CONFIGURE DEVICE TYPE DISK PARALLELISM 3;
  138.  restore database;
  139. !

  140. #至此已经恢复完成


  141. 6、在 primary 和 standby 端添加 standby日志

  142. SQL> alter database add standby logfile
  143. group 4 ('/oracle/product/oradata/zzdb/zzdb_dgredo04.log') size 50m,
  144. group 5 ('/oracle/product/oradata/zzdb/zzdb_dgredo05.log') size 50m,
  145. group 6 ('/oracle/product/oradata/zzdb/zzdb_dgredo06.log') size 50m,
  146. group 7 ('/oracle/product/oradata/zzdb/zzdb_dgredo07.log') size 50m;

  147. SQL> SELECT GROUP#,THREAD#,SEQUENCE#,ARCHIVED,STATUS FROM V$STANDBY_LOG;


  148. 7、在standby端开启实时日志应用

  149. SQL> recover managed standby database using current logfile disconnect from session;
  150. Media recovery complete.

  151.  recover managed standby database disconnect from session;
  152.  alter database recover managed standby database disconnect from session;
  153.  
  154. ---11g 的新功能,它允许物理备库在应用日志时处于只读打开状态,执行以下步骤
  155. startup mount
  156. alter database open;
  157. alter database recover managed standby database using current logfile disconnect;
  158.  
  159. 三、测试ADG

  160. 8、执行日志切换测试(在pri端切换归档,在节点二上检查是否也发生了切换)

  161. alter system switch logfile;
  162. archive log list;

  163. 9、查看standby启动的DG进程

  164. SQL> select process,client_process,sequence#,status from v$managed_standby;

  165. 10、查看数据库的保护模式:

  166. #primary端查看,我们可以看到数据库的保护模式为最大性能
  167. SQL> select database_role,protection_mode,protection_level,open_mode from v$database;

  168. #standby 端查看,也是一样的。

  169. 11、查看DG的日志信息

  170. SQL> select * from v$dataguard_status;

  171. 12、在standby端, Open Read Only standby数据库并且开启实时日志应用
  172. SQL> shutdown immediate
  173. SQL> startup
  174. SQL> select database_role,protection_mode,protection_level,open_mode from v$database;
  175. SQL> select process,client_process,sequence#,status from v$managed_standby;
  176. SQL> alter database recover managed standby database using current logfile disconnect from session;

  177. 13、解锁scott用户,添加数据,验证数据是否能同步

  178. #在primary端创建解锁scott用户并创建测试表t1,插入20000行数据
  179. #primary 端操作如下内容
  180. SQL> set line 100
  181. SQL> select username,default_tablespace,account_status from dba_users where username='SCOTT';
  182. SQL> alter user scott account unlock identified by tiger;
  183. SQL> conn scott/tiger     
  184. SQL> show user
  185. USER is "SCOTT"
  186. SQL> create table t1 (id int primary key, birth char(8));
  187. SQL>
  188. declare
  189. i int;
  190. v_birth varchar2(8);
  191. begin
  192. delete t1;
  193. commit;
  194. for i in 1..20000
  195. loop
  196. insert into t1(id,birth)
  197. values (i ,to_char(to_date('19850101','yyyymmdd')+i,'yyyymmdd'));
  198. commit;
  199. end loop;
  200. end ;
  201. /

  202. #standby端查询scott用户是否解锁,以及t1表是否创建并且插入了10000行数据:
  203. SQL> conn scott/tiger;

  204. SQL> select count(*) from t1;


  205. #至此Oracle 11g ADG就已经配置完成了


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22661144/viewspace-1969250/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/22661144/viewspace-1969250/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值