真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Oracle11gDataGuard使用duplicatefromactivedatabase創(chuàng)建standbydatabase

      用這種方式來搭建DG ,主庫(kù)的停機(jī)時(shí)間很少,只需要重啟一下,使參數(shù)生效。也可以用這種方法進(jìn)行DB遷移。DG搭建好,然后把備庫(kù)激活就可以了。 這樣整個(gè)遷移中宕機(jī)時(shí)間也比較短。

目前創(chuàng)新互聯(lián)公司已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁(yè)空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、高臺(tái)網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

 

       Oracle 11g的pyhsical standby 支持open read only 下的apply和Real-time query。 因此就有了physical standby 穩(wěn)定和logical standby 的報(bào)表查詢功能。

 

Oracle: 11.2.0.1

OS: redhat 5.5

Primary IP: 192.168.2.42

DB_NAME=sanfu

 

Standby IP: 192.168.2.43

DB_NAME=sanfu

 

一.  Primary 端操作:

1. 設(shè)置歸檔模式

       這個(gè)生產(chǎn)庫(kù)都是這種模式。

       SQL> archive log list;

       SQL> shutdown immediate

       SQL> startup mount

       SQL> alter database archivelog;

       SQL> archive log list;

      

2. Primary 設(shè)置force logging

SQL> alter database force logging;

SQL> select force_logging from v$database;

FORCE_LOG

---------

YES

 

3. 配置Oracle Net

       在Primary 庫(kù)和Standby 都要修改。也可以使用netca 和netmgr命令配置。

注意:修改完后記得重啟listener。

 

Listener.ora

[oracle@qs-dmm-rh2 admin]$ cat listener.ora

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost6.localdomain6)(PORT = 1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app/oracle

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = orcl)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)

      (SID_NAME = orcl)

    )

  )

 -- 配置靜態(tài)注冊(cè)

 

tnsname.ora

[oracle@qs-dmm-rh2 admin]$ cat tnsnames.ora

sanfus =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

sanfup =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = orcl)

    )

  )

 

 

4. 添加data guard 參數(shù)

       創(chuàng)建pfile, 添加如下文件:

SQL> create pfile from spfile;

*.db_name='orcl'

*.db_unique_name='sanfup'

*.log_archive_config='dg_config=(sanfup,sanfus)'

*.log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=sanfup'

*.log_archive_dest_2='service=sanfus reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=sanfus'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='sanfus'

*.fal_client='sanfup'

 

 

注意:

       在Oracle 11g的Data Guard中,standby_archive_dest參數(shù)已經(jīng)被取消了。

      

Standby歸檔文件的存放位置按如下規(guī)則來進(jìn)行:

(1)當(dāng)LOG_ARCHIVE_DEST_n設(shè)置了valid_for=(all_logfiles,all_roles),那么在不定義standby_archive_dest參數(shù)時(shí),Oracle就會(huì)選擇LOG_ARCHIVE_DEST_n參數(shù)作為歸檔目標(biāo)。

(2)如果在第一步設(shè)置的同時(shí),又獨(dú)立設(shè)置LOG_ARCHIVE_DEST_n參數(shù)為 valid_for=(standby_logfile,*) 屬性,那么當(dāng)compatible參數(shù)大于10.0的時(shí)候,會(huì)自動(dòng)的選擇任意一個(gè)LOG_ARCHIVE_DEST_n的值。

(3)如果LOG_ARCHIVE_DEST_n 沒有設(shè)置的話,默認(rèn)位置是:

       $ORACLE_HOME/dbs.

       不過valid_for參數(shù)的默認(rèn)值就是all_logfiles和all_roles. 所以只要設(shè)置了本地的歸檔位置,遠(yuǎn)程的歸檔文件也會(huì)放到這個(gè)目錄下面。

 

5. 用新pfile重啟主庫(kù)

 

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initorcl.ora';

File created.

SQL> startup

ORACLE instance started.

 

Total System Global Area  422670336 bytes

Fixed Size                  1336960 bytes

Variable Size             310380928 bytes

Database Buffers          104857600 bytes

Redo Buffers                6094848 bytes

Database mounted.

Database opened.

SQL>

 

 

二.  Standby 端設(shè)置:

 

1. 創(chuàng)建相關(guān)目錄結(jié)構(gòu)

[oracle@qs-dmm-rh3 trace]$ mkdir -p /u01/app/oracle/oradata/dave

--這里我們創(chuàng)建的目錄和Target 庫(kù)不同,我們?cè)趨?shù)文件里需要轉(zhuǎn)換一下。

 

2. 創(chuàng)建standby的口令文件

[oracle@qs-dmm-rh3 trace]$ orapwd file=?/dbs/orapwdave password=oracle

 

3. 創(chuàng)建standby的初始化參數(shù):

*.compatible='11.2.0.4.0'

*db_name=orcl

*.control_files='/u01/app/oracle/oradata/dave/control01.ctl', '/u01/app/oracle/oradata/dave/control02.ctl',

'/u01/app/oracle/oradata/dave/control03.ctl'

*.db_unique_name='sanfus'

*.log_archive_config='dg_config=(sanfup,sanfus)'

*.log_archive_dest_1='location=/u01/archivelog valid_for=(standby_logfile, standby_role) db_unique_name=sanfus'

*.log_archive_dest_2='service=sanfup reopen=120 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=sanfup'

*.log_archive_dest_state_1=enable

*.log_archive_dest_state_2=enable

*.standby_file_management='auto'

*.fal_server='sanfup'

*.fal_client='sanfus'

*.log_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'

*.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/dave'

 

4. 用pfile 將standby 啟動(dòng)到nomount狀態(tài):

SQL> startup nomount pfile=?/dbs/initorcl.ora

ORACLE instance started.

 

Total System Global Area  146472960 bytes

Fixed Size                  1335080 bytes

Variable Size              92274904 bytes

Database Buffers           50331648 bytes

Redo Buffers                2531328 bytes

 

5. 開始duplicate

 

[oracle@qs-dmm-rh3 dbs]$ rman target sys/oracle@sanfup auxiliary sys/oracle@sanfus

 

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 8 16:10:25 2011

 

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

 

connected to target database: ORCL (DBID=1272955137)

connected to auxiliary database: ORCL (not mounted)

 

RMAN> duplicate target database for standby from active database;

 

Starting Duplicate Db at 08-MAR-11

using target database control file instead of recovery catalog

allocated channel: ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: SID=20 device type=DISK

 

contents of Memory Script:

{

   backup as copy reuse

   targetfile  '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format

 '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapworcl'   ;

--用duplicate 創(chuàng)建standby 時(shí)會(huì)復(fù)制口令文件

}

executing Memory Script

 

Starting backup at 08-MAR-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=45 device type=DISK

Finished backup at 08-MAR-11

 

contents of Memory Script:

{

   backup as copy current controlfile for standby auxiliary format  '/u01/app/oracle/oradata/dave/control01.ctl';

   restore clone controlfile to  '/u01/app/oracle/oradata/dave/control02.ctl' from

 '/u01/app/oracle/oradata/dave/control01.ctl';

   restore clone controlfile to  '/u01/app/oracle/oradata/dave/control03.ctl' from

 '/u01/app/oracle/oradata/dave/control01.ctl';

--創(chuàng)建控制文件

}

executing Memory Script

 

Starting backup at 08-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

copying standby control file

output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20110308T161152 RECID=4 STAMP=745258313

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

Finished backup at 08-MAR-11

 

Starting restore at 08-MAR-11

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: copied control file copy

Finished restore at 08-MAR-11

 

Starting restore at 08-MAR-11

using channel ORA_AUX_DISK_1

 

channel ORA_AUX_DISK_1: copied control file copy

Finished restore at 08-MAR-11

 

contents of Memory Script:

{

   sql clone 'alter database mount standby database';

--將備庫(kù)啟動(dòng)到mount standby

}

executing Memory Script

 

sql statement: alter database mount standby database

 

contents of Memory Script:

{

   set newname for tempfile  1 to

 "/u01/app/oracle/oradata/dave/temp01.dbf";

   switch clone tempfile all;

   set newname for datafile  1 to

 "/u01/app/oracle/oradata/dave/system01.dbf";

   set newname for datafile  2 to

 "/u01/app/oracle/oradata/dave/sysaux01.dbf";

   set newname for datafile  3 to

 "/u01/app/oracle/oradata/dave/undotbs01.dbf";

   set newname for datafile  4 to

 "/u01/app/oracle/oradata/dave/users01.dbf";

   backup as copy reuse

   datafile  1 auxiliary format

 "/u01/app/oracle/oradata/dave/system01.dbf"   datafile

 2 auxiliary format

 "/u01/app/oracle/oradata/dave/sysaux01.dbf"   datafile

 3 auxiliary format

 "/u01/app/oracle/oradata/dave/undotbs01.dbf"   datafile

 4 auxiliary format

 "/u01/app/oracle/oradata/dave/users01.dbf"   ;

   sql 'alter system archive log current';

--將datafile convert 到其他目錄

}

executing Memory Script

 

executing command: SET NEWNAME

 

renamed tempfile 1 to /u01/app/oracle/oradata/dave/temp01.dbf in control file

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

executing command: SET NEWNAME

 

Starting backup at 08-MAR-11

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

--開始copy datafile,如果數(shù)據(jù)文件比較大,這個(gè)會(huì)比較慢

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

output file name=/u01/app/oracle/oradata/dave/system01.dbf tag=TAG20110308T161204

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

output file name=/u01/app/oracle/oradata/dave/sysaux01.dbf tag=TAG20110308T161204

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

output file name=/u01/app/oracle/oradata/dave/undotbs01.dbf tag=TAG20110308T161204

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

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

output file name=/u01/app/oracle/oradata/dave/users01.dbf tag=TAG20110308T161204

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

Finished backup at 08-MAR-11

 

sql statement: alter system archive log current

 

contents of Memory Script:

{

   switch clone datafile all;

}

executing Memory Script

 

datafile 1 switched to datafile copy

input datafile copy RECID=4 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/system01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=5 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/sysaux01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=6 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/undotbs01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=7 STAMP=745258432 file name=/u01/app/oracle/oradata/dave/users01.dbf

Finished Duplicate Db at 08-MAR-11

 

RMAN>

 

DG 復(fù)制到這一步已經(jīng)操作完成了。 但是還有一些細(xì)節(jié)需要處理。


兩點(diǎn)注意事項(xiàng):

(1)如果使用的是非catalog,在rman 連接時(shí),加上nocatalog關(guān)鍵字,如:

 

DG2:/home/oracle> rman targetsys/oracle@DG_PD  auxiliarysys/oracle@DG_ST nocatalog

 

Recovery Manager: Release 11.2.0.3.0 -Production on Fri Oct 28 18:46:46 2011

 

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

 

connected to target database: DG(DBID=1679060044)

using target databasecontrol file instead of recovery catalog

connected to auxiliary database: DG (notmounted)

 

不然會(huì)報(bào)如下錯(cuò)誤:

 

DBGSQL:    TARGET> begin :fhdbi := dbms_rcvcat.getDbid; end;

DBGSQL:        sqlcode = 6550

DBGSQL:         B :fhdbi = 32767

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============

RMAN-00571:===========================================================

RMAN-03002: failure of Duplicate Db commandat 10/28/2011 17:53:04

RMAN-05501: aborting duplication of targetdatabase

RMAN-03015: error occurred in stored scriptMemory Script

ORA-06550: line 1, column 17:

PLS-00201: identifier'DBMS_RCVCAT.GETDBID' must be declared

ORA-06550: line 1, column 7:

PL/SQL: Statement ignored

 

(2) 在執(zhí)行duplicate的時(shí)候,如果源庫(kù)和目標(biāo)庫(kù)目錄相同,那么在duplicate 時(shí),需要加上nofilenamecheck,如下:

 

RMAN> duplicate target database for standby from active database dorecover nofilenamecheck;

 

我在上面的示例中,目錄結(jié)構(gòu)不同,所以沒有用該參數(shù),如果目錄相同,而又沒有加該參數(shù),那么就會(huì)報(bào)如下錯(cuò)誤:

 

RMAN> duplicate target database forstandby from active database dorecover nofilenamecheck;

 

RMAN-05501: aborting duplication of targetdatabase

RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/users01.dbf conflicts with a file used by the targetdatabase

RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/undotbs01.dbf conflicts with a file used by thetarget database

RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/sysaux01.dbf conflicts with a file used by thetarget database

RMAN-05001: auxiliary file name/u01/app/oracle/oradata/dg/system01.dbf conflicts with a file used by thetarget database



 

三. 后續(xù)工作

 

1. 主庫(kù)已經(jīng)使用了spfile,但是備庫(kù)用的還是之前的pfile:

Primary:

SQL> show parameter pfile

NAME                                 TYPE    VALUE

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

spfile                               string  /u01/app/oracle/product/11.2.0

 

Standby:

SQL> show parameter pfile

NAME                                 TYPE        VALUE

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

spfile                               string

 

       pfile里面都是我們?cè)O(shè)置的一些基本參數(shù)。 但是備庫(kù)有冗余的作用,所以這里還是建議用主庫(kù)的pfile copy過來,然后修改相關(guān)參數(shù)后,在創(chuàng)建spfile。這樣即使切換了,對(duì)DB的影響也不大。

 

2.  只要備庫(kù)的監(jiān)聽不重啟,重啟備庫(kù)后,主庫(kù)還是能識(shí)別的。 如果備庫(kù)的監(jiān)聽重啟了。那么主庫(kù)也就需要重啟。

 

3. 復(fù)制結(jié)束后的Standby 只啟動(dòng)到mount standby 的狀態(tài)。 并沒有啟動(dòng)MRP的應(yīng)用歸檔程序。 所以這個(gè)時(shí)候查詢主備庫(kù),歸檔是不同步的。需要手動(dòng)的啟動(dòng)MRP進(jìn)程。

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

 

4.  備庫(kù)Standby redo log 問題:

       在duplicate 結(jié)束后,備庫(kù)沒有添加standby redo log file。 但是主庫(kù)采用的是:lgwr async傳送的日志。 當(dāng)備庫(kù)的RFS 進(jìn)程接收到日志后,發(fā)現(xiàn)備庫(kù)沒有standby redo log的時(shí)候,備庫(kù)會(huì)自動(dòng)用ARCH將其寫入歸檔文件。

 

以下是備庫(kù)的alert log:

Tue Mar 08 16:53:32 2011

Archived Log entry 9 added for thread 1 sequence 21 rlc 745174404 ID 0x4bdfd301 dest 2:

RFS[2]: Opened log for thread 1 sequence 22 dbid 1272955137 branch 745174404

Tue Mar 08 16:53:36 2011

Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch2_21_745174404.dbf

Media Recovery Waiting for thread 1 sequence 22 (in transit) --傳輸中

Tue Mar 08 16:58:58 2011

Archived Log entry 10 added for thread 1 sequence 22 rlc 745174404 ID 0x4bdfd301 dest 2:

RFS[2]: Opened log for thread 1 sequence 23 dbid 1272955137 branch 745174404

Tue Mar 08 16:59:00 2011

Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch2_22_745174404.dbf

Media Recovery Waiting for thread 1 sequence 23 (in transit)

-- 注意這里歸檔文件目錄,使用的是$ORACLE_HOME/dbs, 自動(dòng)轉(zhuǎn)換為ARCH時(shí),也是使用默認(rèn)的歸檔目錄。

 

5.  在備庫(kù)添加standby redo log:

SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m;

alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m

*

ERROR at line 1:

ORA-01156: recovery or flashback in progress may need access to files

--在備庫(kù)添加standby redo log需要先停MRP

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo01.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo02.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo03.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/dave/stdbyredo04.log' size 50m;

Database altered.

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

Database altered.

 

在看一下日志:

Tue Mar 08 17:47:39 2011

Archived Log entry 15 added for thread 1 sequence 27 ID 0x4bdfd301 dest 1:

RFS[2]: Selected log 4 for thread 1 sequence 28 dbid 1272955137 branch 745174404

Tue Mar 08 17:47:43 2011

Archived Log entry 16 added for thread 1 sequence 28 ID 0x4bdfd301 dest 1:

Media Recovery Log /u01/archivelog/1_27_745174404.dbf

RFS[2]: Selected log 4 for thread 1 sequence 29 dbid 1272955137 branch 745174404

Media Recovery Log /u01/archivelog/1_28_745174404.dbf

Media Recovery Waiting for thread 1 sequence 29 (in transit)

--我們添加standby redo log 之后,歸檔文件變成了我們指定的Log_archive_dest_n 指定的參數(shù)。

 

6. 在主庫(kù)也添加一下standby redo log

 

SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo01.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo02.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo03.log' size 50m;

Database altered.

SQL> alter database add standby logfile '/u01/app/oracle/oradata/orcl/stdbyredo04.log' size 50m;

Database altered.

 

7. 啟用real-time apply,從而實(shí)現(xiàn)real-time query:

 

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> ALTER DATABASE OPEN;

Database altered.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;

Database altered.

 

8. 驗(yàn)證real-time apply 和real-time query:

 

Primary:

SQL> create table dave(id number,name varchar2(20));

Table created.

SQL> insert into dave values(1,'tianlesoftware');

1 row created.

SQL> commit;

Commit complete.

 

Standby:

SQL> select open_mode from v$database;

OPEN_MODE

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

READ ONLY WITH APPLY

 

SQL> select * from dave;

 

        ID NAME

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

         1 tianlesoftware

 

 

小結(jié):

     11gR2 的物理Data Guard 功能很強(qiáng)大.


新聞標(biāo)題:Oracle11gDataGuard使用duplicatefromactivedatabase創(chuàng)建standbydatabase
當(dāng)前路徑:http://weahome.cn/article/gohdop.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部