溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2020-08-10 14:12:13 來源:ITPUB博客 閱讀:217 作者:cqvienet 欄目:關(guān)系型數(shù)據(jù)庫

 

5、網(wǎng)絡(luò)配置和密碼文件配置

 

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環(huán)境下,密碼文件自動尋找規(guī)則為在$ORACLE_HOME/dbs目錄中的orapw<oracle_sid>文件。

Oracle NET涉及到tnsnames.ora文件和listener.ora兩個文件。tnsnames.ora負(fù)責(zé)提供鏈接本地名,而listener.ora提供監(jiān)聽器靜態(tài)注冊參數(shù)。

 

[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

 

監(jiān)聽器重新啟動。

 

[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

 

下面就可以進(jìn)行恢復(fù)動作了。

 

6、restore backup set

 

啟動rman進(jìn)行還原動作。

 

--連入到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狀態(tài),設(shè)置dbid值。這個取值和Primary數(shù)據(jù)庫的相同。

 

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

 

從備份集合直接恢復(fù)控制文件。

 

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

 

注意兩個現(xiàn)象:首先我們是以standby controlfile的方式,直接從文件系統(tǒng)中讀取備份。第二就是我們并沒有在initora11gsy.ora中配置control_files參數(shù),Oracle直接按照OMF法則創(chuàng)建了控制文件兩個鏡像。第三,這個數(shù)據(jù)沒有寫入到spfile/pfile中,日后給系統(tǒng)帶來了些麻煩。

啟動到mount狀態(tài)。

 

 

RMAN> sql 'alter database mount standby database';

 

sql statement: alter database mount standby database

released channel: ORA_DISK_1

 

最后是比較麻煩的步驟,備份集合中是在Primary的文件路徑,沒有進(jìn)行也沒有途徑進(jìn)行remap動作。所以,Oracle這里面需要手工的對文件進(jìn)行一系列的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目錄結(jié)構(gòu)完全相同,就不需要這個步驟了。之后,如果是10g之前版本,就必須將拷貝過的備份集合放在和原來相同的目錄結(jié)構(gòu)中。如果是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

 

直接恢復(fù)數(shù)據(jù)庫文件。

 

 

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數(shù)據(jù)庫,完成恢復(fù)過程。

 

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

 

7、standby工作配置

 

Standby恢復(fù)完成之后,還要創(chuàng)建專門的standby redo log作為恢復(fù)過程中使用。

 

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狀態(tài),沒有redo log生成。啟動Primarymount狀態(tài)。

 

[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

 

日志情況,特別是日志應(yīng)用情況。

 

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的數(shù)據(jù),已經(jīng)順利傳輸?shù)?/span>ora11gsy端,并且應(yīng)用apply提示標(biāo)志已經(jīng)設(shè)置為YES。在standby端,我們也可以查看應(yīng)用情況。

 

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

 

應(yīng)用成功!但這并不是配置的全部,一些問題在安裝過程中埋下了問題點,一些補充配置也需要后續(xù)完成,才能作為一個健全DG環(huán)境。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI