使用RMAN線上建立DataGuard備用庫(資料檔案不同路徑結構)

djb1008發表於2010-09-09

  1. 環境描述

本文討論的內容建立在兩臺redhat5.3 X86_64伺服器上,資料庫版本為oracle 10.2.0.4

兩個節點都安裝了Oracle Database Server,並在主庫伺服器上建立完DB_NAME=gridctl的資料庫,備庫伺服器只安裝了資料庫軟體,沒有建立資料庫例項,具體的作業系統版本和資料庫版本如下:

#uname -a

Linux standbydb 2.6.18-128.el5 #1 SMP Wed Dec 17 11:41:38 EST 2008 x86_64 x86_64 x86_64 GNU/Linux

SQL> select * from v$version;

BANNER

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

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

PL/SQL Release 10.2.0.4.0 - Production

CORE 10.2.0.4.0 Production

TNS for Linux: Version 10.2.0.4.0 - Production

NLSRTL Version 10.2.0.4.0 - Production

[@more@]

主庫Primary db server:

hostname: primarydb

ip: 168.10.13.192

sid: gridctl

datafile directory: /oradata/gridctl/

備庫Standby db server:

hostname:standbydb

ip: 168.10.13.193

sid: newgridctl

Datafile directory:/oradata/newgridctl/

Two nodes:

#more /etc/hosts

168.10.13.192 primarydb

168.10.13.193 standbydb

DB_NAME=gridctl

ORACLE_HOME:/oracle/product/10.2.0/db_1

Archivelog_dest:/oradata/archivelog/primary_arc

Standby_archivelog_dest:/oradata/archivelog/newstandby_arc

  1. 準備工作

準備工作主要包括主、備資料庫的相關配置檔案(SPFILE,LISTENER.ORA,TNSNAMES.ORAORAPW$ORACLE_SID)的建立或者配置;相關dump檔案路徑和資料檔案路徑的建立;主庫rman全庫備份集生成和standby controlfile生成。

2.1 配置主庫服務 器的spfile,備庫伺服器的spfile

如果主庫與備庫的資料檔案,redo檔案的路徑不相同,需要在備庫伺服器上設定下面三個引數:

*.db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'

*.log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'

*.standby_file_management=AUTO

SQL>alter system set db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/' scope=spfile;

SQL>alter system set log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/' scope=spfile;

SQL>alter system set standby_file_management=AUTO scope=spfile;

[oracle@standbydb dbs]$ more initnewgridctl.ora

*.audit_file_dest='/oracle/admin/newgridctl/adump'

*.background_dump_dest='/oracle/admin/newgridctl/bdump'

*.control_files='/oradata/newgridctl/newstd_control.dbf'

*.core_dump_dest='/oracle/admin/newgridctl/cdump'

*.db_create_file_dest='/oradata/newgridctl'

*.db_name='gridctl'

*.log_archive_dest_1='LOCATION=/oradata/archivelog/primary_arc'

*.log_archive_dest_2='service=standby mandatory reopen=60'

*.standby_archive_dest='/oradata/archivelog/newstandby_arc'

*.user_dump_dest='/oracle/admin/newgridctl/udump'

。。。。。。

*.db_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'

*.log_file_name_convert='/oradata/gridctl/','/oradata/newgridctl/'

*.standby_file_management=AUTO

。。。。。。

2.2 配置主庫伺服器、備庫伺服器的tnsnames.ora,listener.ora

兩個節點的tnsnames.ora的內容都包含下面的內容:

[oracle@ admin]$ more tnsnames.ora

PRIMARY=

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = gridctl)

)

)

NEWSTANDBY=

(DESCRIPTION =

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

(CONNECT_DATA =

(SERVER = DEDICATED)

(SERVICE_NAME = newgridctl)

)

)

兩個節點的listener.ora的內容都包括下面的內容:

[oracle@primarydb admin]$ more listener.ora

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME = gridctl)

(ORACLE_HOME = /oracle/product/10.2.0/db_1)

(SID_NAME = gridctl)

)

)

LISTENER =

(DESCRIPTION =

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

)

[oracle@standbydb admin]$ more listener.ora

SID_LIST_LISTENER =

(SID_LIST =

(SID_DESC =

(GLOBAL_DBNAME =newgridctl)

(ORACLE_HOME = /oracle/product/10.2.0/db_1)

(SID_NAME = newgridctl)

)

)

LISTENER =

(DESCRIPTION =

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

)

2.12.2的內容請參看我的部落格文章"Step Configure DataGuard (10g) Physical Standby Database On Linux X86_64(1/2)",網址為:http://djb1008.itpub.net/post/42280/504822

2.3 在備庫上建立相關資料檔案路徑,dump路徑,將備庫啟動到nomount狀態

[oracle@standbydb ~]$ echo $ORACLE_SID

newgridctl

建立例項newgridctldump檔案存放所需目錄

[oracle@standbydb admin]$ cd /oracle/admin

[oracle@standbydb admin]$ mkdir newgridctl

[oracle@standbydb admin]$ cd newgridctl

[oracle@standbydb newgridctl]$ mkdir adump bdump cdump udump

建立備庫伺服器的資料庫資料檔案存放目錄

[oracle@standbydb oradata]$ cd /oradata

[oracle@standbydb oradata]$ mkdir newgridctl

啟動備庫伺服器的資料庫到nomount狀態

[oracle@standbydb newgridctl]$ sqlplus / as sysdba

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1073741824 bytes

Fixed Size 2089472 bytes

Variable Size 545263104 bytes

Database Buffers 524288000 bytes

Redo Buffers 2101248 bytes

2.4 在主庫使用RMAN 建立一個資料庫備份集

[oracle@primarydb ~]$ rman target /

RMAN> run{

allocate channel d1 type disk;

backup full database format '/oradata/db_%U.bak'

plus archivelog format '/oradata/arc_%U.bak';

Sql 'alter system archive log current';

release channel d1;}

Starting backup at 07-SEP-10

input archive log thread=1 sequence=207 recid=1 stamp=728673992

。。。。。。

input archive log thread=1 sequence=243 recid=59 stamp=729080164

。。。。。。

channel d1: specifying datafile(s) in backupset

input datafile fno=00001 name=/oradata/gridctl/system01.dbf

。。。。。。

input datafile fno=00006 name=/oradata/gridctl/mgmt_ecm_depot1.dbf

piece handle=/oradata/db_0aln9qqi_1_1.bak tag=TAG20100907T105819 comment=NONE

channel d1: backup set complete, elapsed time: 00:00:02

。。。。。。

released channel: d1

2.5 使用rmancopy命令建立一個standby control file

[oracle@primarydb ~]$ rman target /

RMAN> copy current controlfile for standby to '/oradata/newstd_control.ctl';

。。。。。。

output filename=/oradata/newstd_control.ctl tag=TAG20100907T105116 recid=2 stamp=729082276

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 07-SEP-10

2.6 將主庫伺服器的備份集檔案,standby control file透過ftp複製到備庫伺服器。

Ftp 完成後的結果如下:

[oracle@standbydb oradata]$ ls -lt

total 1812612

-rw-r--r-- 1 oracle oinstall 6930432 Sep 7 11:03 newstd_control.ctl

-rw-r--r-- 1 oracle oinstall 7012352 Sep 7 11:03 db_0aln9qqi_1_1.bak

-rw-r--r-- 1 oracle oinstall 581025792 Sep 7 11:02 db_09ln9qqb_1_1.bak

-rw-r--r-- 1 oracle oinstall 629637120 Sep 7 11:02 db_04ln9q5l_1_1.bak

-rw-r--r-- 1 oracle oinstall 629637120 Sep 7 11:02 arc_08ln9qpr_1_1.bak

  1. 執行DUPLICATE命令,建立一個不同目錄結構的standby db

3.1 在主庫上執行DUPLICATE命令前的確認工作

在這裡再次申明一下,執行duplicate操作前,需要檢查幾點內容,如下所述:

Oracleduplcate操作時有點奇怪,怪在那裡呢?

1).要在主庫上執行rman的登入操作,並且auxiliary連線到備庫.

$rman target / auxiliary sys/pwdofsys@standby

2).要在主庫的rman環境裡執行duplicate 命令.

RMAN>run{duplicate target database for standby;}

3). rman的備份集檔案需要複製到備機的相同目錄(不使用主庫伺服器的備份集檔案)

4).檔名稱或者檔案路徑的修改,需要在備庫上設定三個convert引數,主庫不需要設定這些引數。

以上的這4怪,恰恰是rman建立standby db4個陷阱,跳過這四個陷阱,duplicate就順很多。

3.2 在主庫上執行DUPLICATE命令,完成備庫的建立工作

下面就開始執行DUPLICATE命令,進行備庫的建立工作。

[oracle@primarydb oradata]$ rman target / auxiliary sys/aidu2010@newstandby

connected to target database: GRIDCTL (DBID=3373887875)

connected to auxiliary database: GRIDCTL (not mounted)

RMAN> run{

2> duplicate target database for standby;

3> }

Starting Duplicate Db at 07-SEP-10

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=430 devtype=DISK

contents of Memory Script:

{

restore clone standby controlfile;

sql clone 'alter database mount standby database';

}

executing Memory Script

Starting restore at 07-SEP-10

using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: restoring control file

channel ORA_AUX_DISK_1: copied control file copy

input filename=/oradata/newstd_control.ctl

output filename=/oradata/newgridctl/newstd_control.ctl

Finished restore at 07-SEP-10

sql statement: alter database mount standby database

released channel: ORA_AUX_DISK_1

contents of Memory Script:

{

set newname for tempfile 1 to

"/oradata/newgridctl/temp01.dbf";

switch clone tempfile all;

set newname for datafile 1 to

"/oradata/newgridctl/system01.dbf";

set newname for datafile 2 to

"/oradata/newgridctl/undotbs01.dbf";

set newname for datafile 3 to

"/oradata/newgridctl/sysaux01.dbf";

set newname for datafile 4 to

"/oradata/newgridctl/users01.dbf";

set newname for datafile 5 to

"/oradata/newgridctl/mgmt.dbf";

set newname for datafile 6 to

"/oradata/newgridctl/mgmt_ecm_depot1.dbf";

restore

check readonly

clone database

;

}

executing Memory Script

executing command: SET NEWNAME

renamed temporary file 1 to /oradata/newgridctl/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 07-SEP-10

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: sid=430 devtype=DISK

channel ORA_AUX_DISK_1: starting datafile backupset restore

channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00001 to /oradata/newgridctl/system01.dbf

restoring datafile 00002 to /oradata/newgridctl/undotbs01.dbf

restoring datafile 00003 to /oradata/newgridctl/sysaux01.dbf

restoring datafile 00004 to /oradata/newgridctl/users01.dbf

restoring datafile 00005 to /oradata/newgridctl/mgmt.dbf

restoring datafile 00006 to /oradata/newgridctl/mgmt_ecm_depot1.dbf

channel ORA_AUX_DISK_1: reading from backup piece /oradata/db_0dlnaesf_1_1.bak

channel ORA_AUX_DISK_1: restored backup piece 1

piece handle=/oradata/db_0dlnaesf_1_1.bak tag=TAG20100907T164047

channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25

Finished restore at 07-SEP-10

contents of Memory Script:

{

switch clone datafile all;

}

executing Memory Script

datafile 1 switched to datafile copy

input datafile copy recid=12 stamp=729106481 filename=/oradata/newgridctl/system01.dbf

datafile 2 switched to datafile copy

input datafile copy recid=13 stamp=729106481 filename=/oradata/newgridctl/undotbs01.dbf

datafile 3 switched to datafile copy

input datafile copy recid=14 stamp=729106481 filename=/oradata/newgridctl/sysaux01.dbf

datafile 4 switched to datafile copy

input datafile copy recid=15 stamp=729106481 filename=/oradata/newgridctl/users01.dbf

datafile 5 switched to datafile copy

input datafile copy recid=16 stamp=729106481 filename=/oradata/newgridctl/mgmt.dbf

datafile 6 switched to datafile copy

input datafile copy recid=17 stamp=729106481 filename=/oradata/newgridctl/mgmt_ecm_depot1.dbf

Finished Duplicate Db at 07-SEP-10

注意: duplicate命令是在主庫上執行的,而備份集介質需要從備庫的相同目錄(/oradata)取。

3.3 檢查備庫資料庫的狀態和角色

[oracle@standbydb ~]$ sqlplus / as sysdba

SQL> select open_mode,database_role from v$database;

OPEN_MODE DATABASE_ROLE

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

MOUNTED PHYSICAL STANDBY

3.4 在備庫伺服器上執行日誌檔案的介質恢復,與主庫的執行狀態同步。

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

SQL>!

[oracle@standbydb ~]$tail -f alert_newgridctl.log

Wed Sep 8 08:07:07 2010

Media Recovery Log /oradata/archivelog/newstandby_arc1_254_724504451.dbf

Media Recovery Log /oradata/archivelog/newstandby_arc1_255_724504451.dbf

Media Recovery Log /oradata/archivelog/newstandby_arc1_256_724504451.dbf

Media Recovery Log /oradata/archivelog/newstandby_arc1_257_724504451.dbf

Identified End-Of-Redo for thread 1 sequence 257

Wed Sep 8 08:07:07 2010

Media Recovery End-Of-Redo indicator encountered

Wed Sep 8 08:07:07 2010

Media Recovery Applied until change 9886776

Wed Sep 8 08:07:07 2010

MRP0: Media Recovery Complete: End-Of-REDO (newgridctl)

Resetting standby activation ID 3378482509 (0xc95f8d4d)

Wed Sep 8 08:07:08 2010

MRP0: Background Media Recovery process shutdown (newgridctl)

3.5 主、備庫歸檔日誌切換與應用

主庫先進行日誌切換

[oracle@primarydb admin]$ sqlplus / as sysdba

SQL> alter system switch logfile;

System altered.

備庫的alert日誌的應用情況:

[oracle@standbydb bdump]$ tail -f alert_newgridctl.log

Thu Sep 9 10:04:41 2010

RFS[1]: Archived Log: '/oradata/archivelog/newstandby_arc/1_267_724504451.dbf'

Thu Sep 9 10:04:45 2010

Media Recovery Log /oradata/archivelog/newstandby_arc/1_267_724504451.dbf

Media Recovery Waiting for thread 1 sequence 268

查詢備庫資料庫中的日誌應用的情況:

[oracle@standbydb oradata]$ sqlplus / as sysdba

SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

SEQUENCE# FIRST_TIM NEXT_TIME APP

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

267 09-SEP-10 09-SEP-10 YES

1 rows selected.

到此已經使用rman線上(主庫資料庫沒有停機,也不需要停機)建立了一個備庫,並且實現了與主庫的同步。本文對主備庫的切換不做描述,主備庫的切換操作請參看我的另外一遍文章“Step By Step Configure DataGuard (10g) Physical Standby Database On Linux X86_64(2/2) ”,網址為:http://djb1008.itpub.net/post/42280/504948

注: 本文針對的是主備庫資料檔案不同目錄結構,需要設定convert引數;如果主備庫的資料檔案的目錄結構相同,則跳過2.1節的設定convert等引數的環節,其它的照舊執行就可以了。

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

相關文章