ora11_node_dg(1)DG搭建過程

fjzcau發表於2015-12-31


  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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章