使用RMAN備份集搭建Oracle Dataguard Step by Step(二)

煙花丶易冷發表於2014-05-28

 

5、網路配置和密碼檔案配置

 

PrimaryStandby端在sys使用者管理密碼上要求相同,所以在密碼檔案問題上,直接複製命名是支援的。

 

[oracle@SimpleLinux oracle]$ cd $ORACLE_HOME/dbs

[oracle@SimpleLinux dbs]$ ls -l

total 9552

-rw-rw----. 1 oracle oinstall    1544 May 24 21:12 hc_ora11g.dat

-rw-rw----. 1 oracle oinstall    1544 May 24 21:20 hc_ora11gsy.dat

-rw-r--r--. 1 oracle oinstall    2851 May 15  2009 init.ora

-rw-r--r--. 1 oracle oinstall     774 May 24 21:17 initora11g.ora

-rw-r--r--. 1 oracle oinstall     774 May 24 21:18 initora11gsy.ora

-rw-r-----. 1 oracle oinstall      24 Apr  1 12:39 lkORA11G

-rw-r-----. 1 oracle oinstall    1536 Apr  1 12:45 orapwora11g

-rw-r-----. 1 oracle oinstall 9748480 May 24 20:47 snapcf_ora11g.f

-rw-r-----. 1 oracle oinstall    3584 May 24 21:13 spfileora11g.ora

[oracle@SimpleLinux dbs]$ cp orapwora11g orapwora11gsy

 

Linux環境下,密碼檔案自動尋找規則為在$ORACLE_HOME/dbs目錄中的orapw檔案。

Oracle NET涉及到tnsnames.ora檔案和listener.ora兩個檔案。tnsnames.ora負責提供連結本地名,而listener.ora提供監聽器靜態註冊引數。

 

[oracle@SimpleLinux 2014_05_24]$ cd /u01/app/oracle/network/admin/

[oracle@SimpleLinux admin]$ ls -l

total 20

-rw-r--r--. 1 oracle oinstall  345 May 24 22:50 listener.ora

-rw-r--r--. 1 oracle oinstall  345 Apr  1 13:10 listener.ora.bk

drwxr-xr-x. 2 oracle oinstall 4096 Apr  1 12:27 samples

-rw-r--r--. 1 oracle oinstall  381 Dec 17  2012 shrept.lst

-rw-r--r--. 1 oracle oinstall  502 May 24 22:49 tnsnames.ora

 

兩個檔案上分別配置好ora11gora11gsy資訊。

 

[oracle@SimpleLinux admin]$ cat tnsnames.ora

# tnsnames.ora Network Configuration File: /u01/app/oracle/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

 

ORA11GSY =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.88)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = ora11gsy)

    )

  )

 

ORA11G =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.137.88)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = ora11g)

    )

  )

 

[oracle@SimpleLinux admin]$ cat listener.ora

# listener.ora Network Configuration File: /u01/app/oracle/network/admin/listener.ora

# Generated by Oracle configuration tools.

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = SimpleLinux)(PORT = 1521))

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

  )

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = ora11g)

      (ORACLE_HOME = /u01/app/oracle)

      (PROGRAM = extproc)

      (GLOBAL_DBNAME = ora11g)

    ) 

 

    (SID_DESC =

      (SID_NAME = ora11gsy)

      (ORACLE_HOME = /u01/app/oracle)

      (GLOBAL_DBNAME = ora11gsy)

    )

  )

 

 

ADR_BASE_LISTENER = /u01/app

 

監聽器重新啟動。

 

[oracle@SimpleLinux admin]$ lsnrctl stop

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2014 22:52:14

 

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SimpleLinux)(PORT=1521)))

The command completed successfully

[oracle@SimpleLinux admin]$ lsnrctl start

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2014 22:52:23

(篇幅原因,有省略……

 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SimpleLinux)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Services Summary...

Service "ora11g" has 1 instance(s).

  Instance "ora11g", status UNKNOWN, has 1 handler(s) for this service...

Service "ora11gsy" has 1 instance(s).

  Instance "ora11gsy", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully

 

下面就可以進行恢復動作了。

 

6restore backup set

 

啟動rman進行還原動作。

 

--連入到ora11gsy

[oracle@SimpleLinux ~]$ export ORACLE_SID=ora11gsy

[oracle@SimpleLinux ~]$ rman target /

 

Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 24 21:32:23 2014

 

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

 

connected to target database (not started)

 

啟動到nomount狀態,設定dbid值。這個取值和Primary資料庫的相同。

 

RMAN> startup nomount

Oracle instance started

 

Total System Global Area     372449280 bytes

 

Fixed Size                     1364732 bytes

Variable Size                301993220 bytes

Database Buffers              62914560 bytes

Redo Buffers                   6176768 bytes

 

 

RMAN> set dbid=4239941846

executing command: SET DBID

 

從備份集合直接恢復控制檔案。

 

RMAN> restore standby controlfile from '/standbybackup/o1_mf_ncnnf_TAG20140524T204716_9r156r7j_.bkp';

 

Starting restore at 24-MAY-14

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=1 device type=DISK

 

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:07

output file name=/u01/app/oradata/ORA11GSY/controlfile/o1_mf_9r18tmv6_.ctl

output file name=/u01/app/fast_recovery_area/ORA11GSY/controlfile/o1_mf_9r18tpkf_.ctl

Finished restore at 24-MAY-14

 

注意兩個現象:首先我們是以standby controlfile的方式,直接從檔案系統中讀取備份。第二就是我們並沒有在initora11gsy.ora中配置control_files引數,Oracle直接按照OMF法則建立了控制檔案兩個映象。第三,這個資料沒有寫入到spfile/pfile中,日後給系統帶來了些麻煩。

啟動到mount狀態。

 

 

RMAN> sql 'alter database mount standby database';

 

sql statement: alter database mount standby database

released channel: ORA_DISK_1

 

最後是比較麻煩的步驟,備份集合中是在Primary的檔案路徑,沒有進行也沒有途徑進行remap動作。所以,Oracle這裡面需要手工的對檔案進行一系列的set newname動作。

 

RMAN> run {

2> ALLOCATE CHANNEL c1 DEVICE TYPE DISK ;

3> set newname for datafile 1 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_system_9mnjrzty_.dbf';

4> set newname for datafile 2 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9mnjs04h_.dbf';

5> set newname for datafile 3 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9mnjs068_.dbf';

6> set newname for datafile 4 to '/u01/app/oradata/ORA11GSY/datafile/o1_mf_users_9mnjs074_.dbf';

7>

8> }

 

allocated channel: c1

channel c1: SID=20 device type=DISK

 

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

released channel: c1

 

如果PrimaryStandby目錄結構完全相同,就不需要這個步驟了。之後,如果是10g之前版本,就必須將複製過的備份集合放在和原來相同的目錄結構中。如果是10g之後,就可以使用catalog backuppiece人工的載入備份集合。

 

RMAN> catalog backuppiece '/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp';

 

cataloged backup piece

backup piece handle=/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp RECID=3 STAMP=848442509

 

直接恢復資料庫檔案。

 

 

RMAN> run {

2> restore database;

3> switch datafile all;

4> }

 

Starting restore at 24-MAY-14

using channel ORA_DISK_1

 

(篇幅原因,有省略……

channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9mnjs04h_.dbf

channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9mnjs068_.dbf

channel ORA_DISK_1: reading from backup piece /standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp

 

channel ORA_DISK_1: piece handle=/standbybackup/o1_mf_nnndf_TAG20140524T204320_9r14z9hn_.bkp tag=TAG20140524T204320

channel ORA_DISK_1: restored backup piece 1

channel ORA_DISK_1: restore complete, elapsed time: 00:08:25

Finished restore at 24-MAY-14

 

recover資料庫,完成恢復過程。

 

RMAN> restore database;     

 

Starting restore at 24-MAY-14

using channel ORA_DISK_1

 

skipping datafile 1; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_system_9r1cgl8x_.dbf

skipping datafile 2; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_sysaux_9r1cgld1_.dbf

skipping datafile 3; already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_undotbs1_9r1cglfr_.dbf

datafile 4 is already restored to file /u01/app/oradata/ORA11GSY/datafile/o1_mf_users_9r1c6gb9_.dbf

restore not done; all files read only, offline, or already restored

Finished restore at 24-MAY-14

 

7standby工作配置

 

Standby恢復完成之後,還要建立專門的standby redo log作為恢復過程中使用。

 

SQL> alter database add standby logfile size 50m;

Database altered

 

SQL> alter database add standby logfile size 50m;

Database altered

 

 

SQL> select group#, sequence#, dbid from v$standby_log;

    GROUP#  SEQUENCE# DBID

---------- ---------- ----------------------------------------

         4          0 UNASSIGNED

         5          0 UNASSIGNED

 

啟動standbyrecover動作。

 

SQL> alter database recover managed standby database using current logfile disconnect from session;

 

Database altered.

 

 

SQL> select name, OPEN_MODE, database_role from v$database;

 

NAME      OPEN_MODE            DATABASE_ROLE

--------- -------------------- ----------------

ORA11G    MOUNTED              PHYSICAL STANDBY

 

Primary全過程始終處在mount狀態,沒有redo log生成。啟動Primarymount狀態。

 

[oracle@SimpleLinux ~]$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.4.0 Production on Sat May 24 23:06:49 2014

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

SQL> conn / as sysdba

Connected.

SQL> alter database open;

Database altered.

 

Primary端傳輸通道是否正常檢視v$archived_dest_status

 

SQL> col dest_name for a20;

SQL> select dest_id, dest_name, status, type, database_mode, recovery_mode, DESTINATION from v$archive_dest_status where dest_id<3;

 

   DEST_ID DEST_NAME            STATUS    TYPE           DATABASE_MODE   RECOVERY_MODE           DESTINATION

---------- -------------------- --------- -------------- --------------- ----------------------- --------------------------------------------------------------------------------

         1 LOG_ARCHIVE_DEST_1   VALID     LOCAL          OPEN            IDLE                    /u01/app/oracle/dbs/arch

         2 LOG_ARCHIVE_DEST_2   VALID     PHYSICAL       MOUNTED-STANDBY MANAGED REAL TIME APPLY ora11gsy

 

日誌情況,特別是日誌應用情況。

 

SQL> select recid,name, sequence#, STANDBY_DEST, ARCHIVED, APPLIED from v$archived_log;

 

     RECID NAME                                                                              SEQUENCE# STANDBY_DEST ARCHIVED APPLIED

---------- -------------------------------------------------------------------------------- ---------- ------------ -------- ---------

         1 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_6_9r1fdo70_.arc          6 NO           YES      NO

         2 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_7_9r1fdvt1_.arc          7 NO           YES      NO

         3 ora11gsy                                                                                  6 YES          YES      YES

         4 ora11gsy                                                                                  7 YES          YES      YES

         5 /u01/app/fast_recovery_area/ORA11G/archivelog/2014_05_24/o1_mf_1_8_9r1fmzv9_.arc          8 NO           YES      NO

         6 ora11gsy                                                                                  8 YES          YES      YES

 

6 rows selected

 

sequence#=6-8的資料,已經順利傳輸到ora11gsy端,並且應用apply提示標誌已經設定為YES。在standby端,我們也可以檢視應用情況。

 

SQL> conn sys/oracle@ora11gsy as sysdba

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0

Connected as SYS

 

SQL> select recid,name, sequence#, STANDBY_DEST, ARCHIVED, APPLIED from v$archived_log;

 

     RECID NAME                                                                              SEQUENCE# STANDBY_DEST ARCHIVED APPLIED

---------- -------------------------------------------------------------------------------- ---------- ------------ -------- ---------

         1 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_6_9r1ff3t6_.a          6 NO           YES      YES

         2 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_7_9r1ff3dn_.a          7 NO           YES      YES

         3 /u01/app/fast_recovery_area/ORA11GSY/archivelog/2014_05_24/o1_mf_1_8_9r1fn28z_.a          8 NO           YES      YES

 

 

SQL> select group#, dbid, sequence# from v$standby_log;

 

    GROUP# DBID                                      SEQUENCE#

---------- ---------------------------------------- ----------

         4 4239941846                                        9

         5 UNASSIGNED                                        0

 

應用成功!但這並不是配置的全部,一些問題在安裝過程中埋下了問題點,一些補充配置也需要後續完成,才能作為一個健全DG環境。


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

相關文章