使用rman duplicate创建物理active standby dataguard

2024-02-09 19:08

本文主要是介绍使用rman duplicate创建物理active standby dataguard,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

11g的rman提供duplicate可以快速创建物理dataguard。简单方便,dataguard要求主库和备库的db_name一致,db_unique_name不同,下面是具体步骤

基本环境如下:

主库:
hostname:11g1
ip:192.168.56.35
db_name:squan
sid=squan
db_unique_name=squan
备库:
hostname:11g2
ip:192.168.56.106
db_name:squan
sid=suq

db_unique_name=suq

==============================

一、主库的基本步骤:

1.修改数据库为force logging

2.创建密码文件

3.创建standby logfile,standby logfile的组数比联机日志多一组

4.修改tnsname.ora,添加一个到standby数据库的服务命名

5.修改standby的相关参数

具体操作如下:

1.修改数据库为force logging
SQL> alter database force logging;Database altered.2.创建密码文件
[oracle@11g1 dbs]$ orapwd file=orapwsquan password=manager entries=10SQL> select * from v$log;GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE	  MEMBERS ARC STATUS	       FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1	    1	      47   52428800	   512		1 YES ACTIVE		     1170031 24-MAY-14	    1172488 24-MAY-142	    1	      48   52428800	   512		1 NO  CURRENT		     1172488 24-MAY-14	 2.8147E+143.创建standby logfile
SQL> alter database add standby logfile group 3 ('/opt/oracle/oradata/squan/stand_redo03.log') size 50m;Database altered.SQL> alter database add standby logfile group 4 ('/opt/oracle/oradata/squan/stand_redo04.log') size 50m;Database altered.SQL> alter database add standby logfile group 5 ('/opt/oracle/oradata/squan/stand_redo05.log') size 50m;Database altered.4.修改tnsname.ora
[oracle@11g1 admin]$ cat tnsnames.ora 
# tnsnames.ora Network Configuration File: /opt/oracle/product/OraHome/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.SQUAN =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 11g1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = squan)))11g2=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 11g2)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = suq)))11g1=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 11g1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = squan)))5.修改standby的相关参数  
SQL> alter system set log_archive_config='dg_config=(squan,suq)' scope=both;  --罗列dg中的所有的db_unique_nameSystem altered.SQL> alter system set log_archive_dest_1='location=/opt/arch valid_for=(all_logfiles,all_roles) db_unique_name=squan' scope=both;System altered.SQL> alter system set log_archive_dest_2='service=11g2 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=suq' scope=both;System altered.SQL>  alter system set fal_server=squan scope=both;System altered.SQL> alter system set fal_client=suq scope=both;System altered.SQL> show parameter db_name                   --如果db_name没有设置,那么需要设置,并且重启数据库生效NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_name 			     string	 squan

二、备库的基本步骤

1.配置静态监听

2.配置密码文件

3.修改参数文件并启动实例到nomount

具体步骤如下:


1.配置静态监听
[oracle@11g2 admin]$ cat listener.ora 
# listener.ora Network Configuration File: /opt/oracle/product/OraHome/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =(SID_LIST =(SID_DESC =(SID_NAME = PLSExtProc)(ORACLE_HOME = /opt/oracle/product/OraHome11204)(PROGRAM = extproc))(SID_DESC =(SID_NAME = suq)(ORACLE_HOME = /opt/oracle/product/OraHome11204)(GLOBAL_DBNAME=suq)))LISTENER =(DESCRIPTION_LIST =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 11g2)(PORT = 1521))))ADR_BASE_LISTENER = /opt/oracle[oracle@11g2 ~]$ lsnrctl statusLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-5月 -2014 21:32:21Copyright (c) 1991, 2013, Oracle.  All rights reserved.正在连接到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=11g2)(PORT=1521)))
LISTENER 的 STATUS
------------------------
别名                      LISTENER
版本                      TNSLSNR for Linux: Version 11.2.0.4.0 - Production
启动日期                  24-5月 -2014 18:58:46
正常运行时间              0 天 2 小时 33 分 35 秒
跟踪级别                  off
安全性                    ON: Local OS Authentication
SNMP                      OFF
监听程序参数文件          /opt/oracle/product/OraHome11204/network/admin/listener.ora
监听程序日志文件          /opt/oracle/diag/tnslsnr/11g2/listener/alert/log.xml
监听端点概要...(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=11g2)(PORT=1521)))
服务摘要..
服务 "PLSExtProc" 包含 1 个实例。实例 "PLSExtProc", 状态 UNKNOWN, 包含此服务的 1 个处理程序...
服务 "suq" 包含 2 个实例。实例 "suq", 状态 UNKNOWN, 包含此服务的 1 个处理程序...实例 "suq", 状态 BLOCKED, 包含此服务的 1 个处理程序...
命令执行成功
2.配置密码文件,直接从主库拷贝然后改名
[oracle@11g2 dbs]$ scp 11g1:`pwd`/orapwsquan .
The authenticity of host '11g1 (192.168.56.35)' can't be established.
RSA key fingerprint is 73:56:4c:3a:01:3f:50:c8:d8:3a:5d:d5:21:00:6a:fe.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '11g1' (RSA) to the list of known hosts.
oracle@11g1's password: 
orapwsquan                                                                                                     100% 2560     2.5KB/s   00:00    
[oracle@11g2 dbs]$ mv orapwsquan orapwsuq<pre name="code" class="sql">3.修改参数文件并启动实例到nomount
[oracle@11g2 dbs]$ cat initsuq.ora 
*.__db_cache_size=314572800
*.__java_pool_size=4194304
*.__large_pool_size=4194304
*.__oracle_base='/opt/oracle' #ORACLE_BASE set from environment
*.__pga_aggregate_target=490733568
*.__sga_target=583008256
*.__shared_io_pool_size=0
*.__shared_pool_size=239075328
*.__streams_pool_size=8388608
*.audit_file_dest='/opt/oracle/admin/suq/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/opt/oracle/oradata/suq/control01.ctl','/opt/oracle/flash_recovery_area/squan/control02.ctl'#Restore Controlfile
*.db_block_size=8192
*.db_domain=''
*.db_name='squan'         #db_name需要和主库一致
*.db_unique_name='suq'    #db_unique_name必须不同
*.db_recovery_file_dest='/opt/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=5218762752
*.diagnostic_dest='/opt/oracle'
*.fal_client='SUQ'
*.fal_server='SQUAN'
*.log_archive_config='dg_config=(squan,suq)'
*.log_archive_dest_1='location=/opt/arch valid_for=(all_logfiles,all_roles) db_unique_name=suq'
*.log_archive_dest_2='service=11g1 lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=squan'
*.memory_target=1073741824
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.db_file_name_convert='/opt/oracle/oradata/squan','/opt/oracle/oradata/suq'  #设置数据文件名字转换
*.log_file_name_convert='/opt/oracle/oradata/squan','/opt/oracle/oradata/suq' #设置日志文件名字转换
*.standby_file_management='AUTO'        #文件自动管理


 
[oracle@11g2 dbs]$ export ORACLE_SID=suq 
[oracle@11g2 dbs]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on 星期六 5月 24 21:30:45 2014Copyright (c) 1982, 2013, Oracle.  All rights reserved.已连接到空闲例程。SQL>  startup nomount pfile='initsuq.ora'
ORACLE 例程已经启动。Total System Global Area 1068937216 bytes
Fixed Size		    2260088 bytes
Variable Size		  746587016 bytes
Database Buffers	  314572800 bytes
Redo Buffers		    5517312 bytes
SQL> exit

三、使用duplicate创建standby database

在源端rman连接源库和备库,发起duplicate:

[oracle@11g1 admin]$ rman target /Recovery Manager: Release 11.2.0.4.0 - Production on Sat May 24 21:50:04 2014Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.connected to target database: SQUAN (DBID=3808450041)RMAN> connect auxiliary sys/manager@11g2connected to auxiliary database: SQUAN (not mounted)RMAN> duplicate target database for standby from active database;Starting Duplicate Db at 24-MAY-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=134 device type=DISKcontents of Memory Script:
{backup as copy reusetargetfile  '/opt/oracle/product/OraHome11204/dbs/orapwsquan' auxiliary format '/opt/oracle/product/OraHome11204/dbs/orapwsuq'   ;
}
executing Memory ScriptStarting backup at 24-MAY-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
Finished backup at 24-MAY-14contents of Memory Script:
{backup as copy current controlfile for standby auxiliary format  '/opt/oracle/oradata/suq/control01.ctl';restore clone controlfile to  '/opt/oracle/flash_recovery_area/squan/control02.ctl' from '/opt/oracle/oradata/suq/control01.ctl';
}
executing Memory ScriptStarting backup at 24-MAY-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/opt/oracle/product/OraHome11204/dbs/snapcf_squan.f tag=TAG20140524T215011 RECID=7 STAMP=848440211
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 24-MAY-14Starting restore at 24-MAY-14
using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 24-MAY-14contents of Memory Script:
{sql clone 'alter database mount standby database';
}
executing Memory Scriptsql statement: alter database mount standby databasecontents of Memory Script:
{set newname for tempfile  1 to "/opt/oracle/oradata/suq/temp01.dbf";switch clone tempfile all;set newname for datafile  1 to "/opt/oracle/oradata/suq/system01.dbf";set newname for datafile  2 to "/opt/oracle/oradata/suq/sysaux01.dbf";set newname for datafile  3 to "/opt/oracle/oradata/suq/undotbs01.dbf";set newname for datafile  4 to "/opt/oracle/oradata/suq/users01.dbf";set newname for datafile  5 to "/opt/oracle/oradata/suq/test02.dbf";set newname for datafile  6 to "/opt/oracle/oradata/suq/test01.dbf";backup as copy reusedatafile  1 auxiliary format "/opt/oracle/oradata/suq/system01.dbf"   datafile 2 auxiliary format "/opt/oracle/oradata/suq/sysaux01.dbf"   datafile 3 auxiliary format "/opt/oracle/oradata/suq/undotbs01.dbf"   datafile 4 auxiliary format "/opt/oracle/oradata/suq/users01.dbf"   datafile 5 auxiliary format "/opt/oracle/oradata/suq/test02.dbf"   datafile 6 auxiliary format "/opt/oracle/oradata/suq/test01.dbf"   ;sql 'alter system archive log current';
}
executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /opt/oracle/oradata/suq/temp01.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 24-MAY-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/opt/oracle/oradata/squan/system01.dbf
output file name=/opt/oracle/oradata/suq/system01.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/opt/oracle/oradata/squan/sysaux01.dbf
output file name=/opt/oracle/oradata/suq/sysaux01.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/opt/oracle/oradata/squan/undotbs01.dbf
output file name=/opt/oracle/oradata/suq/undotbs01.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/opt/oracle/oradata/squan/users01.dbf
output file name=/opt/oracle/oradata/suq/users01.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/opt/oracle/oradata/squan/test02.dbf
output file name=/opt/oracle/oradata/suq/test02.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/opt/oracle/oradata/squan/test01.dbf
output file name=/opt/oracle/oradata/suq/test01.dbf tag=TAG20140524T215020
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 24-MAY-14sql statement: alter system archive log currentcontents of Memory Script:
{switch clone datafile all;
}
executing Memory Scriptdatafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=848440398 file name=/opt/oracle/oradata/suq/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=848440398 file name=/opt/oracle/oradata/suq/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=848440398 file name=/opt/oracle/oradata/suq/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=848440398 file name=/opt/oracle/oradata/suq/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=848440398 file name=/opt/oracle/oradata/suq/test02.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=12 STAMP=848440398 file name=/opt/oracle/oradata/suq/test01.dbf
Finished Duplicate Db at 24-MAY-14

四、开启standby日志应用

duplicate完成之后备库数据库启动到mount阶段,这时候就可以开启应用日志,最后再重启打开到read only并应用日志:

SQL> select status from v$Instance;STATUS
------------
MOUNTEDSQL> select database_role from v$database;DATABASE_ROLE
----------------
PHYSICAL STANDBYSQL> alter database recover managed standby database disconnect from session;数据库已更改。SQL> alter database open read only;
alter database open read only
*
第 1 行出现错误:
ORA-10456: cannot open standby database; media recovery session may be in
progressSQL> alter database recover managed standby database cancel;数据库已更改。SQL> alter database open read only;数据库已更改。SQL> alter database recover managed standby database disconnect from session;数据库已更改。


五、standby数据库基本管理

查看主库日志传输状态:
SQL> SELECT dest_id,dest_name,status,target,destination,ERROR,db_unique_name FROM v$archive_dest WHERE ROWNUM<3;DEST_ID DEST_NAME	     STATUS    TARGET  DESTINATION     ERROR	  DB_UN
------- -------------------- --------- ------- --------------- ---------- -----1 LOG_ARCHIVE_DEST_1   VALID     PRIMARY /opt/arch		  squan2 LOG_ARCHIVE_DEST_2   VALID     STANDBY 11g2			  suq查看角色和打开模式:
SQL> select DATABASE_ROLE,PROTECTION_MODE,open_mode from v$database; DATABASE_ROLE	 PROTECTION_MODE      OPEN_MODE
---------------- -------------------- --------------------
PHYSICAL STANDBY MAXIMUM PERFORMANCE  READ ONLY WITH APPLY开启应用:
SQL> alter database recover managed standby database disconnect from session;开启实时应用:
SQL>recover managed standby database using current logfile disconnect from session;关闭应用:
SQL> alter database recover managed standby database cancel;查看是否有gap:
SQL>SELECT * FROM v$archive_gap;查看归档日志是否被应用:
SQL>SELECT NAME,thread#,sequence#,first_time,next_time,applied FROM v$archived_log ORDER BY 1,2;fail over:
SQL> alter database recover managed standby database finish ;
SQL> alter database recover managed standby database finish force;
SQL> alter database commit to switchover to primary;standby进程状态:
SQL>SELECT pid, PROCESS, STATUS, THREAD#, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY where process='RFS' or process='MRP0';







这篇关于使用rman duplicate创建物理active standby dataguard的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/695058

相关文章

vue使用docxtemplater导出word

《vue使用docxtemplater导出word》docxtemplater是一种邮件合并工具,以编程方式使用并处理条件、循环,并且可以扩展以插入任何内容,下面我们来看看如何使用docxtempl... 目录docxtemplatervue使用docxtemplater导出word安装常用语法 封装导出方

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

使用Jackson进行JSON生成与解析的新手指南

《使用Jackson进行JSON生成与解析的新手指南》这篇文章主要为大家详细介绍了如何使用Jackson进行JSON生成与解析处理,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 核心依赖2. 基础用法2.1 对象转 jsON(序列化)2.2 JSON 转对象(反序列化)3.

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

Elasticsearch 在 Java 中的使用教程

《Elasticsearch在Java中的使用教程》Elasticsearch是一个分布式搜索和分析引擎,基于ApacheLucene构建,能够实现实时数据的存储、搜索、和分析,它广泛应用于全文... 目录1. Elasticsearch 简介2. 环境准备2.1 安装 Elasticsearch2.2 J

使用C#代码在PDF文档中添加、删除和替换图片

《使用C#代码在PDF文档中添加、删除和替换图片》在当今数字化文档处理场景中,动态操作PDF文档中的图像已成为企业级应用开发的核心需求之一,本文将介绍如何在.NET平台使用C#代码在PDF文档中添加、... 目录引言用C#添加图片到PDF文档用C#删除PDF文档中的图片用C#替换PDF文档中的图片引言在当

Java中List的contains()方法的使用小结

《Java中List的contains()方法的使用小结》List的contains()方法用于检查列表中是否包含指定的元素,借助equals()方法进行判断,下面就来介绍Java中List的c... 目录详细展开1. 方法签名2. 工作原理3. 使用示例4. 注意事项总结结论:List 的 contain

C#使用SQLite进行大数据量高效处理的代码示例

《C#使用SQLite进行大数据量高效处理的代码示例》在软件开发中,高效处理大数据量是一个常见且具有挑战性的任务,SQLite因其零配置、嵌入式、跨平台的特性,成为许多开发者的首选数据库,本文将深入探... 目录前言准备工作数据实体核心技术批量插入:从乌龟到猎豹的蜕变分页查询:加载百万数据异步处理:拒绝界面

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

Python使用自带的base64库进行base64编码和解码

《Python使用自带的base64库进行base64编码和解码》在Python中,处理数据的编码和解码是数据传输和存储中非常普遍的需求,其中,Base64是一种常用的编码方案,本文我将详细介绍如何使... 目录引言使用python的base64库进行编码和解码编码函数解码函数Base64编码的应用场景注意