热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

Oracle11gDataGuard使用duplicatefromactivedatabase创建st

Oracle11g的pyhsicalstandby支持openreadonly下的apply和Real-timequery。因此就有了physicalstandby稳定和logicalst

Oracle 11g的pyhsical standby 支持open read only 下的apply和Real-time query。 因此就有了physical standby 稳定和logical st

用这种方式来搭建DG ,主库的停机时间很少,只需要重启一下,使参数生效。也可以用这种方法进行DB迁移。DG搭建好,然后把备库激活就可以了。 这样整个迁移中宕机时间也比较短。

Oracle 11g的pyhsical standby 支持open read only 下的apply和Real-time query。 因此就有了physical standby 稳定和logical standby 的报表查询功能。

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. 设置归档模式

这个生产库都是这种模式。

SQL> archive log list;

SQL> shutdown immediate

SQL> startup mount

SQL> alter database archivelog;

SQL> archive log list;

2. Primary 设置force logging

SQL> alter database force logging;

SQL> select force_logging from v$database;

FORCE_LOG

---------

YES

3. 配置Oracle Net

在Primary 库和Standby 都要修改。也可以使用netca 和netmgr命令配置。

注意:修改完后记得重启listener。

Listener.ora

[oracle@qs-dmm-rh1 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)

)

)

-- 配置静态注册

tnsname.ora

[oracle@qs-dmm-rh1 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 参数

创建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参数已经被取消了。

Standby归档文件的存放位置按如下规则来进行:

(1)当LOG_ARCHIVE_DEST_n设置了valid_for=(all_logfiles,all_roles),那么在不定义standby_archive_dest参数时,Oracle就会选择LOG_ARCHIVE_DEST_n参数作为归档目标。

(2)如果在第一步设置的同时,又独立设置LOG_ARCHIVE_DEST_n参数为 valid_for=(standby_logfile,*) 属性,那么当compatible参数大于10.0的时候,会自动的选择任意一个LOG_ARCHIVE_DEST_n的值。

(3)如果LOG_ARCHIVE_DEST_n 没有设置的话,默认位置是:

$ORACLE_HOME/dbs.

不过valid_for参数的默认值就是all_logfiles和all_roles. 所以只要设置了本地的归档位置,远程的归档文件也会放到这个目录下面。

5. 用新pfile重启主库

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 端设置:

1. 创建相关目录结构

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

--这里我们创建的目录和Target 库不同,我们在参数文件里需要转换一下。

2. 创建standby的口令文件

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

3. 创建standby的初始化参数:

*.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 启动到nomount状态:

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-rh2 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 创建standby 时会复制口令文件

}

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';

--创建控制文件

}

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';

--将备库启动到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,如果数据文件比较大,这个会比较慢

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 复制到这一步已经操作完成了。 但是还有一些细节需要处理。

两点注意事项:


(1)如果使用的是非catalog,在rman 连接时,加上nocatalog关键字,如:

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)

不然会报如下错误:

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) 在执行duplicate的时候,如果源库和目标库目录相同,那么在duplicate 时,需要加上nofilenamecheck,如下:


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

我在上面的示例中,目录结构不同,所以没有用该参数,如果目录相同,而又没有加该参数,那么就会报如下错误:


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

三. 后续工作

1. 主库已经使用了spfile,但是备库用的还是之前的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里面都是我们设置的一些基本参数。 但是备库有冗余的作用,所以这里还是建议用主库的pfile copy过来,然后修改相关参数后,在创建spfile。这样即使切换了,对DB的影响也不大。

2. 只要备库的监听不重启,重启备库后,主库还是能识别的。 如果备库的监听重启了。那么主库也就需要重启。

3. 复制结束后的Standby 只启动到mount standby 的状态。 并没有启动MRP的应用归档程序。 所以这个时候查询主备库,归档是不同步的。需要手动的启动MRP进程。

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

4. 备库Standby redo log 问题:

推荐阅读
  • 数据输入验证与控件绑定方法
    本文提供了多种数据输入验证函数及控件绑定方法的实现代码,包括电话号码、数字、传真、邮政编码、电子邮件和网址的验证,以及报表绑定和自动编号等功能。 ... [详细]
  • binlog2sql,你该知道的数据恢复工具
    binlog2sql,你该知道的数据恢复工具 ... [详细]
  • 在Android应用开发过程中,开发者经常遇到诸如CPU使用率过高、内存泄漏等问题。本文将介绍几种常用的命令及其应用场景,帮助开发者有效定位并解决问题。 ... [详细]
  • 【MySQL】frm文件解析
    官网说明:http:dev.mysql.comdocinternalsenfrm-file-format.htmlfrm是MySQL表结构定义文件,通常frm文件是不会损坏的,但是如果 ... [详细]
  • 本文详细介绍了如何在Oracle数据库中使用SQL进行分页查询,通过嵌套查询和ROWNUM函数的应用,实现数据的高效分页展示。 ... [详细]
  • hlg_oj_1116_选美大赛这题是最长子序列,然后再求出路径就可以了。开始写的比较乱,用数组什么的,后来用了指针就好办了。现在把代码贴 ... [详细]
  • 本文详细探讨了在Java中如何将图像对象转换为文件和字节数组(Byte[])的技术。虽然网络上存在大量相关资料,但实际操作时仍需注意细节。本文通过使用JMSL 4.0库中的图表对象作为示例,提供了一种实用的方法。 ... [详细]
  • 长期从事ABAP开发工作的专业人士,在面对行业新趋势时,往往需要重新审视自己的发展方向。本文探讨了几位资深专家对ABAP未来走向的看法,以及开发者应如何调整技能以适应新的技术环境。 ... [详细]
  • 本文探讨了如何将个人经历,特别是非传统的职业路径,转化为职业生涯中的优势。通过作者的亲身经历,展示了舞蹈生涯对商业思维的影响。 ... [详细]
  • Windows Phone 弹出窗口实现方案
    在当前版本的 Silverlight for Windows Phone 中,由于缺乏对 ChildWindow 的支持,开发者需要采用其他方法来实现弹出窗口的功能。本文将探讨几种有效的解决方案。 ... [详细]
  • 龙蜥社区开发者访谈:技术生涯的三次蜕变 | 第3期
    龙蜥社区的开发者们通过自己的实践和经验,推动着开源技术的发展。本期「龙蜥开发者说」聚焦于一位资深开发者的三次技术转型,分享他在龙蜥社区的成长故事。 ... [详细]
  • Markdown 编辑技巧详解
    本文介绍如何使用 Typora 编辑器高效编写 Markdown 文档,包括代码块的插入方法等实用技巧。Typora 官方网站:https://www.typora.io/ 学习资源:https://www.markdown.xyz/ ... [详细]
  • 本文介绍了ADO.NET框架中的五个关键组件:Connection、Command、DataAdapter、DataSet和DataReader。每个组件都在数据访问和处理过程中扮演着不可或缺的角色。 ... [详细]
  • empty,isset首先都会检查变量是否存在,然后对变量值进行检测。而is_null只是直接检查变量值,是否为null,因此如果变量未定义就会出现错误!检测一个变量是否是null ... [详细]
  • XenDesktop部署与管理经验分享
    本文详细介绍了XenDesktop的安装步骤,包括在管理员权限下进行虚拟桌面配置、域登录及VDA安装等关键操作,并探讨了个人磁盘模式下的镜像更新策略,以及如何正确处理应用程序和快捷方式的权限设置。 ... [详细]
author-avatar
高度的寂寞
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有