手把手教你安裝Data Guard

oracle_zsx發表於2013-12-18


(1)
主庫安裝資料庫,備庫只安裝軟體,我們可以採用在主庫裝完軟體的時候對虛擬機器進行復制。
主庫在用dbca建庫的時候,全域性資料庫選擇szscpdb,sid選擇szsc。




(2)
配置主庫和備庫資訊
主庫:
作業系統:oracle liunx 5.6
主機名:SZSCPDB
ip地址:192.168.1.21
oracle_sid:szsc
db_unqiue_name:szscpdb
service_name:szscpdb
global_name:szscpdb
監聽名、埠:listener、1521


備庫:
作業系統:oracle liunx 5.6
主機名:SZSCSTB
ip地址:192.168.1.22
oracle_sid:szsc
db_unqiue_name:szscstb
service_name:szscstb
global_name:szscstb
監聽名、埠:listener、1521




(3)
檢視主庫和備庫的hosts檔案,確定ip和主機名的解析:
主庫:
[oracle@SZSCPDB szscpdb]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.1.21    SZSCPDB
192.168.1.22    SZSCSTB


備庫:
[oracle@SZSCSTB szscstb]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.1.21    SZSCPDB
192.168.1.22    SZSCSTB




(4)
確定主庫的監聽是開啟的
[oracle@SZSCPDB szscpdb]$ lsnrctl status


LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2013 15:30:42


Copyright (c) 1991, 2011, Oracle.  All rights reserved.


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SZSCPDB)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                15-DEC-2013 14:24:29
Uptime                    0 days 1 hr. 6 min. 12 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/SZSCPDB/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SZSCPDB)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "szscXDB" has 1 instance(s).
  Instance "szsc", status READY, has 1 handler(s) for this service...
Service "szscpdb" has 2 instance(s).
  Instance "szsc", status UNKNOWN, has 1 handler(s) for this service...
  Instance "szsc", status READY, has 1 handler(s) for this service...
The command completed successfully




(5)
配置主庫為歸檔模式:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/szscpdb
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence           5




(6)
更改主庫為force logging
SQL> alter database force logging;
Database altered.




(7)
建立主庫的密碼檔案
[root@SZSCPDB dbs]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[root@SZSCPDB dbs]# orapwd file=$ORACLE_HOME/dbs/orapwszsc password=oracle entries=30;




(8)
修改主庫的監聽檔案,請確保有SID_LIST_LISTENER:
[root@SZSCPDB dbs]# cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[root@SZSCPDB admin]# vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = szscpdb)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = szsc)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = SZSCPDB)(PORT = 1521))
    )
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
ADR_BASE_LISTENER = /u01/app/oracle




(9)
修改主庫的tnsname檔案:
[root@SZSCPDB admin]# vi tnsnames.ora 
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.


SZSCPDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = szscpdb)
    )
  )


SZSCSTB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = szscstb)
    )
  )




(10)
修改主庫的引數檔案:
[root@SZSCPDB admin]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
szsc.__db_cache_size=192937984
szsc.__java_pool_size=4194304
szsc.__large_pool_size=4194304
szsc.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
szsc.__pga_aggregate_target=209715200
szsc.__sga_target=306184192
szsc.__shared_io_pool_size=0
szsc.__shared_pool_size=96468992
szsc.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/szscpdb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/szscpdb/control01.ctl','/u01/app/oracle/oradata/szscpdb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='szscpdb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=szscXDB)'
*.log_archive_config='dg_config=(szscpdb,szscstb)'
*.log_archive_dest_1='LOCATION=/arch/szscpdb LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=szscpdb'
*.log_archive_dest_2='SERVICE=SZSCSTB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=szscstb'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscstb/','/u01/app/oracle/oradata/szscpdb/'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscstb/','/u01/app/oracle/oradata/szscpdb/'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=512753664
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.standby_file_management='AUTO'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.fal_server=szscstb
*.fal_client=szscpdb
*.db_unique_name=szscpdb


注意:
1、
log_archive_dest_2='SERVICE=SZSCSTB
這個引數就是tnsnames的別名,就是這個檔案開頭的那個大寫的名字。


2、
*.fal_server=szscstb
*.fal_client=szscpdb
這兩個引數是各自的service_name。




(11)
傳輸主庫的引數檔案、密碼檔案以及tnsname檔案到備庫上:
[oracle@SZSCPDB dbs]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
scp initszsc.ora orapwszsc SZSCSTB:$ORACLE_HOME/dbs


[oracle@SZSCPDB ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
scp tnsnames.ora SZSCSTB:$ORACLE_HOME/network/admin




(12)
修改備庫的引數檔案:
[root@SZSCSTB admin]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[root@SZSCSTB dbs]# vi initszsc.ora 
szsc.__db_cache_size=192937984
szsc.__java_pool_size=4194304
szsc.__large_pool_size=4194304
szsc.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
szsc.__pga_aggregate_target=209715200
szsc.__sga_target=306184192
szsc.__shared_io_pool_size=0
szsc.__shared_pool_size=96468992
szsc.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/szscstb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/szscstb/control01.ctl','/u01/app/oracle/oradata/szscstb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='szscpdb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=szscXDB)'
*.log_archive_config='dg_config=(szscpdb,szscstb)'
*.log_archive_dest_1='LOCATION=/arch/szscstb LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=szscstb'
*.log_archive_dest_2='SERVICE=SZSCPDB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=szscpdb'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscpdb/','/u01/app/oracle/oradata/szscstb/'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscpdb/','/u01/app/oracle/oradata/szscstb/'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=512753664
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.standby_file_management='AUTO'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.fal_server=szscpdb
*.fal_client=szscstb
*.db_unique_name=szscstb




(13)
在備庫上建立相應的目錄,因為備庫開始沒有建立資料庫,有些目錄是引數檔案中沒有的。
1、
audit_file_dest:
[oracle@SZSCSTB ~]$ mkdir -p /u01/app/oracle/admin/szscstb/adump/


2、
control_files:
[oracle@SZSCSTB ~]$ mkdir -p /u01/app/oracle/oradata/szscstb


3、
建立一個備份檔案的位置,等會主庫會將備份傳遞過來:
[root@SZSCSTB ~]# mkdir  /backup
[root@SZSCSTB ~]# chown -R oracle:oinstall /backup


4、
建立一個歸檔目錄,接收主庫傳遞的歸檔日誌:
[root@SZSCSTB ~]# mkdir -p /arch/szscstb
[root@SZSCSTB ~]# chown -R oracle:oinstall /arch/szscstb




(15)
在主庫上用rman做一個全備,也需要建立備份的目錄:
[root@SZSCPDB ~]# mkdir  /backup
[root@SZSCPDB ~]# chown -R oracle:oinstall /backup


RMAN>backup device type disk format '/backup/%U' database plus archivelog;
 


(16)
將主庫的備份檔案傳遞到備庫上:
[oracle@SZSCPDB admin]$ cd /backup/
[oracle@SZSCPDB backup]$ scp * SZSCSTB:/backup




(17)
將備庫啟動到nomount狀態:
[root@SZSCSTB ~]# su - oracle
[oracle@SZSCSTB ~]$ sqlplus / as sysdba
SQL> startup nomount;




(18)
修改備庫的監聽檔案。
[oracle@SZSCSTB admin]$ vi listener.ora 
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = szscstb)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = szsc)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = SZSCSTB)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )
ADR_BASE_LISTENER = /u01/app/oracle




(19)
啟動監聽,確保服務名註冊無誤)
[oracle@SZSCSTB ~]$ lsnrctl start


LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2013 07:42:41


Copyright (c) 1991, 2011, Oracle.  All rights reserved.


Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SZSCSTB)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                15-DEC-2013 06:13:05
Uptime                    0 days 1 hr. 29 min. 36 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/SZSCSTB/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SZSCSTB)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "szscXDB" has 1 instance(s).
  Instance "szsc", status READY, has 1 handler(s) for this service...
Service "szscstb" has 2 instance(s).
  Instance "szsc", status UNKNOWN, has 1 handler(s) for this service...
  Instance "szsc", status READY, has 1 handler(s) for this service...
The command completed successfully




(20)
主庫應用備份檔案到備庫上,使用duplicate方式(在主庫上執行)
RMAN> connect auxiliary sys/oracle@SZSCSTB    
connected to auxiliary database: SZSCPDB (not mounted)
RMAN> duplicate target database for standby;
Starting Duplicate Db at 08-MAR-13
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 08-MAR-13
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 /BACKUP/0lo3vm4i_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0lo3vm4i_1_1 tag=TAG20130308T022752
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output file name=/u01/app/oracle/oradata/szscstb/control01.ctl
output file name=/u01/app/oracle/oradata/szscstb/control02.ctl
Finished restore at 08-MAR-13
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/szscstb/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/u01/app/oracle/oradata/szscstb/system01.dbf";
   set newname for datafile  2 to 
 "/u01/app/oracle/oradata/szscstb/sysaux01.dbf";
   set newname for datafile  3 to 
 "/u01/app/oracle/oradata/szscstb/undotbs01.dbf";
   set newname for datafile  4 to 
 "/u01/app/oracle/oradata/szscstb/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/szscstb/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 08-MAR-13
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 //u01/app/oracle/oradata/szscstb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/szscstb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/szscstb/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/szscstb/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/0ko3vm18_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0ko3vm18_1_1 tag=TAG20130308T022752
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 08-MAR-13
contents of Memory Script.:
{
   switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/users01.dbf
Finished Duplicate Db at 08-MAR-13




(21)
執行備庫恢復模式。(在備庫上執行)
SQL> select instance_name,status from v$instance;
INSTANCE_NAME    STATUS
---------------- ------------
szsc               MOUNTED


SQL> alter database recover managed standby database disconnect from session;
Database altered.




(22)
檢視日誌同步情況,確保日誌都應用了。
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED
  2  FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
 SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
        13 RFS     15-DEC-13 15-DEC-13 YES
        14 RFS     15-DEC-13 15-DEC-13 YES
        15 RFS     15-DEC-13 15-DEC-13 YES
        16 RFS     15-DEC-13 15-DEC-13 YES
        17 RFS     15-DEC-13 15-DEC-13 YES
        18 RFS     15-DEC-13 15-DEC-13 YES
        19 RFS     15-DEC-13 15-DEC-13 YES
        20 RFS     15-DEC-13 15-DEC-13 YES
        21 RFS     15-DEC-13 15-DEC-13 YES
        22 RFS     15-DEC-13 15-DEC-13 YES




(23)
建立standby logfile。主庫和備庫都要新增。
主庫:
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo01.log' size 512M; 
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo02.log' size 512M; 
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo03.log' size 512M; 
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo04.log' size 512M;


備庫:
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo01.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo02.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo03.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo04.log' size 512M;




(24)
實現日誌同步。(備庫上執行)
SQL> alter database recover managed standby database disconnect from session;


完成之後,結束這個恢復程式:
SQL> alter database recover managed standby database cancel;


將備庫啟動到open read only的狀態。
SQL> alter database open read only;




(25)
檢視主庫和備庫的日誌同步情況,確保已經同步。(如果沒有同步,繼續第24步)
主庫:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/szscpdb
Oldest online log sequence     21
Next log sequence to archive   23
Current log sequence           23


備庫:
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/szscstb
Oldest online log sequence     21
Next log sequence to archive   0
Current log sequence           23


在備庫上執行:
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED
  2  FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
 SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
        13 RFS     15-DEC-13 15-DEC-13 YES
        14 RFS     15-DEC-13 15-DEC-13 YES
        15 RFS     15-DEC-13 15-DEC-13 YES
        16 RFS     15-DEC-13 15-DEC-13 YES
        17 RFS     15-DEC-13 15-DEC-13 YES
        18 RFS     15-DEC-13 15-DEC-13 YES
        19 RFS     15-DEC-13 15-DEC-13 YES
        20 RFS     15-DEC-13 15-DEC-13 YES
        21 RFS     15-DEC-13 15-DEC-13 YES
        22 RFS     15-DEC-13 15-DEC-13 YES




(26)
確認資料可以同步,在主庫上建立一張表,看備庫上是否可以檢視到。
主庫:
SQL> create table zsx (id number);
Table created.


備庫:
SQL> desc zsx
ERROR:
ORA-04043: object zsx does not exist


注意:
發現資料沒有同步,請執行下面27,接收資料。




(27)
備庫上接收資料,並自動同步:
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.


SQL> desc zsx
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                                 NUMBER




(28)
再次驗證資料是否同步。
主庫:
SQL> insert into zsx values(1);
1 row created.


SQL> commit;
Commit complete.


備庫:
SQL> select * from zsx;
        ID
----------
         1




(29)
如果28步沒有問題,那麼就代表你的DG配置成功了。下一階段就是實現switchover了。

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

相關文章