rhel6.4-11.2.0.3-RAC搭建單節點DG

龍山游龍發表於2015-07-10
RAC搭建單節點備庫ADG(active data guard)
掌握DG的核心思想,不管是單節點-單節點、RAC-單節點還是RAC-RAC,都差不多,本質是一樣的,come on
1、/etc/hosts RAC和備機保持一致即可
2、修改資料庫為強制日誌模式
SQL> select force_logging from v$database
SQL> alter database force logging
3、修改資料庫處於歸檔模式
SQL> select open_mode,log_mode from v$database;
4、在主庫上修改引數檔案
-------------------------------------------------------------------------------
Primary Database: Primary Role Initialization Parameters
-------------------------------------------------------------------------------
DB_NAME=chicago
DB_UNIQUE_NAME=chicago
LOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'
CONTROL_FILES='/arch1/chicago/control1.ctl', '/arch2/chicago/control2.ctl'
LOG_ARCHIVE_DEST_1=
 'LOCATION=/arch1/chicago/
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
  DB_UNIQUE_NAME=chicago'
LOG_ARCHIVE_DEST_2=
 'SERVICE=boston ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=boston'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_FORMAT=%t_%s_%r.arc
LOG_ARCHIVE_MAX_PROCESSES=30
-------------------------------------------------------------------------------
Primary Database: Standby Role Initialization Parameters
-------------------------------------------------------------------------------
FAL_SERVER=boston
DB_FILE_NAME_CONVERT='boston','chicago'
LOG_FILE_NAME_CONVERT=
 '/arch1/boston/','/arch1/chicago/','/arch2/boston/','/arch2/chicago/'
STANDBY_FILE_MANAGEMENT=AUTO
-------------------------------------------------------------------------------

SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora11g,beiku)';
SQL> show parameter LOG_ARCHIVE_DEST_1
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=+data/ora11g/archivelog/ #歸檔位置可人為指定 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ora11g';
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=beiku ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=beiku';
SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=spfile;
SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=spfile;
SQL> alter system set REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE scope=spfile;
SQL> show parameter LOG_ARCHIVE_FORMAT                           #  靜態引數,重啟生效
SQL> alter system set LOG_ARCHIVE_MAX_PROCESSES=30 scope=spfile;
-----------------------------------------------------------
SQL> alter system set fal_server=beiku scope=spfile;
SQL> alter system set fal_client=ora11g scope=spfile;            #  fal_client設定本身,fal_server是對方,檢查歸檔是否斷檔
SQL> ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO SCOPE=SPFILE;    
SQL> ALTER SYSTEM SET DB_FILE_NAME_CONVERT='+data/ora11g/','/oracle/app/beiku/' scope =spfile;    #靜態引數,重啟生效
SQL> ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='+data/ora11g/','/oracle/app/beiku/' scope =spfile;  #靜態引數,重啟生效
5、配置監聽lisener.ora、配置網路服務名tnsnames.ora
通常使用netca來進行配置,特殊情況手工配置
主備機相互驗證tnsping service_names
6、將主機$ORACLE_HOME/dbs/下的密碼檔案orapwORACLE_SID傳至備機,可以用ssh/ftp
7、在主機/home/oracle下建立控制檔案並且傳至備機/home/oracle
SQL> alter database create standby controlfile as '/home/oracle/control01.ctl';
8、在主機/tmp下建立初始化引數檔案,並且傳至備機$ORACLE_HOME/dbs/下
SQL> create pfile='/tmp/initORACLE_SID.ora' from spfile;
9、修改備機初始化引數檔案
-------------------------------------------------------------------------------
Modifying Initialization Parameters for a Physical Standby Database
-------------------------------------------------------------------------------
DB_NAME=chicago
DB_UNIQUE_NAME=boston
LOG_ARCHIVE_CONFIG='DG_CONFIG=(chicago,boston)'
CONTROL_FILES='/arch1/boston/control1.ctl', '/arch2/boston/control2.ctl'
DB_FILE_NAME_CONVERT='chicago','boston'
LOG_FILE_NAME_CONVERT=
 '/arch1/chicago/','/arch1/boston/','/arch2/chicago/','/arch2/boston/'
LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
LOG_ARCHIVE_DEST_1=
 'LOCATION=/arch1/boston/
  VALID_FOR=(ALL_LOGFILES,ALL_ROLES)
  DB_UNIQUE_NAME=boston'
LOG_ARCHIVE_DEST_2=
 'SERVICE=chicago ASYNC
  VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)
  DB_UNIQUE_NAME=chicago'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
STANDBY_FILE_MANAGEMENT=AUTO
FAL_SERVER=chicago
-------------------------------------------------------------------------------
*.audit_file_dest='/oracle/app/admin/beiku/adump'
*.audit_trail='db'
*.cluster_database=false
*.compatible='11.2.0.0.0'
*.control_files='/oracle/app/beiku/control01.ctl', '/oracle/app/beiku/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='ora11g'
*.diagnostic_dest='/oracle/app'
*.log_archive_max_processes=30
*.memory_target=1264582656
*.open_cursors=300
*.processes=150
*.remote_listener='node-scan:1521'
*.remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
DB_UNIQUE_NAME=beiku
LOG_ARCHIVE_CONFIG='DG_CONFIG=(ora11g,beiku)'
DB_FILE_NAME_CONVERT='+data/ora11g/','/oracle/app/beiku/'
LOG_FILE_NAME_CONVERT='+data/ora11g/','/oracle/app/beiku/'
LOG_ARCHIVE_FORMAT=log%t_%s_%r.arc
LOG_ARCHIVE_DEST_1='LOCATION=/arch1/beiku/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=beiku'
LOG_ARCHIVE_DEST_2='SERVICE=ora11g ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ora11g'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=ENABLE
STANDBY_FILE_MANAGEMENT=AUTO
FAL_SERVER=ora11g
-------------------------------------------------------------------------------
10、在主機做資料庫的備份集並且把備份集傳至備機/home/oracle
[oracle@node2 ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Jul 10 15:21:21 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORA11G (DBID=4275958693)

RMAN> backup database format  '/home/oracle/racfull_%s_%p';
11、在備機用RMAN做複製STANDBY資料庫操作
注:要用使用者名稱和密碼(sys/oracle)連線主庫和備庫
[oracle@jason ~]$ rman target sys/oracle@ora11g auxiliary sys/oracle

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Jul 10 14:13:15 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORA11G (DBID=4275958693)
connected to auxiliary database: ORA11G (not mounted) #備庫啟到nomount階段,例項已經起來

RMAN> duplicate target database for standby;

Starting Duplicate Db at 10-JUL-15
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK

contents of Memory Script:
{
   restore clone standby controlfile;
}
executing Memory Script

Starting restore at 10-JUL-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/racfull_8_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/racfull_8_1 tag=TAG20150710T122559
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/app/beiku/control01.ctl
output file name=/oracle/app/beiku/control02.ctl
Finished restore at 10-JUL-15

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
 "/oracle/app/beiku/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/oracle/app/beiku/system01.dbf";
   set newname for datafile  2 to
 "/oracle/app/beiku/sysaux01.dbf";
   set newname for datafile  3 to
 "/oracle/app/beiku/undotbs01.dbf";
   set newname for datafile  4 to
 "/oracle/app/beiku/users01.dbf";
   set newname for datafile  5 to
 "/oracle/app/beiku/undotbs02.dbf";
   set newname for datafile  6 to
 "/oracle/app/beiku/jason01.dbf";
   restore
   clone database
   ;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /oracle/app/beiku/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 10-JUL-15
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/app/beiku/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/app/beiku/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/app/beiku/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/app/beiku/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /oracle/app/beiku/undotbs02.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /oracle/app/beiku/jason01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /home/oracle/racfull_7_1
channel ORA_AUX_DISK_1: piece handle=/home/oracle/racfull_7_1 tag=TAG20150710T122559
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 10-JUL-15

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

datafile 1 switched to datafile copy
input datafile copy RECID=10 STAMP=884700883 file name=/oracle/app/beiku/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=11 STAMP=884700883 file name=/oracle/app/beiku/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=12 STAMP=884700883 file name=/oracle/app/beiku/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=13 STAMP=884700883 file name=/oracle/app/beiku/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=14 STAMP=884700883 file name=/oracle/app/beiku/undotbs02.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=15 STAMP=884700883 file name=/oracle/app/beiku/jason01.dbf
Finished Duplicate Db at 10-JUL-15

RMAN>
結束後會自動將備庫啟到mount狀態
SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
beiku            MOUNTED
開啟備庫,此時備庫正處在最大效能模式
SQL> alter database open read only;     #11gDG已經可以在open的狀態下應用歸檔

Database altered.

SQL> select protection_mode,database_role,open_mode from v$database;

PROTECTION_MODE      DATABASE_ROLE    OPEN_MODE
-------------------- ---------------- --------------------
MAXIMUM PERFORMANCE  PHYSICAL STANDBY READ ONLY

SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> select sequence#,thread#,applied from v$archived_log;  #在主庫雙節點分別切換日誌alter system switch logfile,在備庫顯示如下,DG已執行正常

 SEQUENCE#    THREAD# APPLIED
---------- ---------- ---------
       121          1 YES
       119          1 YES
       120          1 YES
       118          1 YES
       122          1 YES
       151          2 YES
       149          2 YES
       150          2 YES
       152          2 YES
       153          2 YES
       154          2 YES

 SEQUENCE#    THREAD# APPLIED
---------- ---------- ---------
       155          2 YES
       156          2 YES
       157          2 YES
       123          1 YES
       158          2 YES
       159          2 YES
       160          2 YES
       161          2 YES
       162          2 YES
       163          2 YES
       164          2 YES

 SEQUENCE#    THREAD# APPLIED
---------- ---------- ---------
       124          1 YES
       125          1 YES
       126          1 YES
       165          2 YES
       127          1 YES
       128          1 YES
12、配置DG為最大可用模式
在備庫要建立STANDBY REDO LOGFILE
SQL> select group#,member from v$logfile;

    GROUP# MEMBER
---------- --------------------------------------------------
         2 /oracle/app/beiku/redo02.log
         1 /oracle/app/beiku/redo01.log
         3 /oracle/app/beiku/redo03.log
         4 /oracle/app/beiku/redo04.log
SQL> alter database add standby logfile group 5 ('/oracle/app/beiku/standby_redo05.log')  size 50m;
SQL> alter database add standby logfile group 6 ('/oracle/app/beiku/standby_redo06.log')  size 50m;
SQL> alter database add standby logfile group 7 ('/oracle/app/beiku/standby_redo07.log')  size 50m;
SQL> alter database add standby logfile group 8 ('/oracle/app/beiku/standby_redo08.log')  size 50m;
SQL> alter database add standby logfile group 9 ('/oracle/app/beiku/standby_redo09.log')  size 50m;
SQL> alter database set standbydatabase to maximize availability;
SQL> alter database recover managedstandby database using current logfile disconnect from session;  #啟動實時恢復
SQL>alter database recover managed standby database cancel;
接下來就是驗證階段和主備切換
有需要,就繼續研究吧

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30310891/viewspace-1728967/,如需轉載,請註明出處,否則將追究法律責任。

相關文章