9. Oracle DataGuard的介绍
一. Oracle DataGuard简介
Oracle DataGuard;简称DG。是由一个Primary Database(主库)和一个或者多个Standby Database(备库)组成。对Oracle来说;本身不能提高性能。通过数据冗余来保护数据。由Primary Database对外提供服务;用户操作在Primary Database上操作;其操作的数据库Redo Log或者Archive log通过网络传输到Standby Database。Standby Database在重做这些日志。从而实现Primary Database和Standby Database数据同步。
架构图如下:
Oracle DataGuard中的Standby库有两种:物理Standby和逻辑Standby。
- 逻辑Standby接收后将其转换成SQL语句,在Standby数据库上执行SQL语句实现同步,这种方式叫SQL Apply。
- 物理Standby接收完Primary数据库生成的REDO数据后,以介质恢复的方式实现同步,这种方式也叫Redo Apply。
二. Oracle DataGuard搭建
安装规划:
IP | ROLE |
192.168.1.235 | Primary |
192.168.1.221 | Standby |
2.1. 主库设置归档模式
alter database archivelog;
2.2. 主库设置Force Logging模式
alter database force logging;
2.3. 备库创建相应的dump文件夹
# 在主库查询对应的dump目录
select name, value
from v$parameter
where name in ('audit_file_dest',
'background_dump_dest',
'control_files',
'core_dump_dest',
'user_dump_dest',
'db_recovery_file_dest'
)
ORDER BY name ASC;
# 备库用oracle用户执行创建目录
mkdir -p $value
2.4. 配置Standby Redologs
对于模式中最大保护和最高可用性;采用是 LGWR 模式传送 Redo 日志;需要为 Standby库配置 Standby Redologs。Standby Redologs 和 ONline Redologs 文件大小是相同的。比 ONline Redologs 个数要 +1 。
# 查看redologs日志信息
SQL> select group#,type,member from v$logfile; GROUP# TYPE MEMBER
------ ---------- --------------------------------------------------
1 ONLINE /u01/app/oradata/ora235/redo01.log
2 ONLINE /u01/app/oradata/ora235/redo02.log
3 ONLINE /u01/app/oradata/ora235/redo03.log SQL> select group#,bytes from v$log; GROUP# BYTES
------ ----------
1 52428800
2 52428800
3 52428800
# 添加Standby Redologs;添加如下:
ALTER DATABASE ADD STANDBY LOGFILE GROUP 4('/u01/app/oradata/ora235/stdred001.log') SIZE 50 M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 5('/u01/app/oradata/ora235/stdred002.log') SIZE 50 M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 6('/u01/app/oradata/ora235/stdred003.log') SIZE 50 M;
ALTER DATABASE ADD STANDBY LOGFILE GROUP 7('/u01/app/oradata/ora235/stdred004.log') SIZE 50 M;
2.5. 创建实例密钥文件
- 主库生成密钥文件
orapwd FILE=/u01/app/oracle/dbs/orapwora235 password=li0924 entries=5;
- 将密钥文件传输到备库
scp /u01/app/oracle/dbs/orapwora235 oracle@192.168.1.221:/u01/app/oracle/dbs
2.6. 创建参数文件
本文采用 Primary 库和 Standby 库采用相同路径;所以仅设置必要的参数。
- 主库通过spfile生成pfile文件
create pfile from spfile;
- 添加Primary端的pfile内容如下
*.DB_UNIQUE_NAME=db_primary
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(db_primary,db_standby)'
*.LOG_ARCHIVE_DEST_2='SERVICE=tns_standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby'
*.LOG_ARCHIVE_DEST_STATE_2=DEFER
*.LOG_FILE_NAME_CONVERT ='/u01/app/oradata/ora235/','/u01/app/oradata/ora235/'
*.FAL_SERVER=tns_standby
*.FAL_CLIENT=tns_primary
*.STANDBY_FILE_MANAGEMENT=AUTO
- Primary重新启动
primary>create spfile from pfile; File created. primary>startup
ORACLE instance started. Total System Global Area 780824576 bytes
Fixed Size 2257312 bytes
Variable Size 511708768 bytes
Database Buffers 264241152 bytes
Redo Buffers 2617344 bytes
Database mounted.
Database opened.
- 复制参数文件到Standby库
scp /u01/app/oracle/dbs/initora235.ora oracle@192.168.1.221:/u01/app/oracle/dbs
- 添加Standby端的pfile内容如下
*.DB_UNIQUE_NAME=db_standby
*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(db_primary,db_standby)'
*.LOG_ARCHIVE_DEST_2='SERVICE=tns_primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_primary'
*.LOG_FILE_NAME_CONVERT ='/u01/app/oradata/ora235/','/u01/app/oradata/ora235/'
*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
*.FAL_SERVER=tns_primary
*.FAL_CLIENT=tns_standby
*.STANDBY_FILE_MANAGEMENT=AUTO
- 将Standby端启动到nomount状态
[oracle@oracle221 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Aug 9 22:56:49 2018 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount;
ORACLE instance started. Total System Global Area 780824576 bytes
Fixed Size 2257312 bytes
Variable Size 511708768 bytes
Database Buffers 264241152 bytes
Redo Buffers 2617344 bytes
2.7 配置主备库的监听文件和网络文件
- 设置Primary库和Standby库的service_name
SQL> show parameter service_name; NAME TYPE VALUE
------------------------------------ ----------- ---------------
service_names string lottu
SQL> alter system set service_names='db_primary' scope=both; System altered. SQL> show parameter service_name; NAME TYPE VALUE
------------------------------------ ----------- ----------------
service_names string db_primary
- 备库的service_name设置为db_standby;需要到参数文件修改。
*.service_names='db_standby'
- Primary库配置listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.235)(PORT = 1521)(IP = FIRST)))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
) SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ora235)
(GLOBAL_DBNAME = db_primary)
(ORACLE_HOME =/u01/app/oracle)
)
)
- Standby库配置listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.221)(PORT = 1521)(IP = FIRST)))
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
) SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ora235)
(GLOBAL_DBNAME = db_standby)
(ORACLE_HOME =/u01/app/oracle)
)
)
- Primary库和Standby库设置tnsname.ora
tns_primary=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.235)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = db_primary)
)
(HS = OK)
) tns_standby=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.221)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = db_standby)
)
(HS = OK)
)
重启监听lsnrctl restart
2.8. 克隆Standby库
在Primary库执行
[oracle@oracle235 admin]$ rman target sys/li0924@tns_primary auxiliary sys/li0924@tns_standby Recovery Manager: Release 11.2.0.4.0 - Production on Thu Aug 9 23:56:46 2018 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORA235 (DBID=2047494122)
connected to auxiliary database: ORA235 (not mounted) RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK; Starting Duplicate Db at 09-AUG-18
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/dbs/orapwora235' auxiliary format
'/u01/app/oracle/dbs/orapwora235' ;
}
executing Memory Script Starting backup at 09-AUG-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=26 device type=DISK
Finished backup at 09-AUG-18 contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/u01/app/oradata/ora235/control01.ctl';
restore clone controlfile to '/u01/app/oradata/ora235/control02.ctl' from
'/u01/app/oradata/ora235/control01.ctl';
}
executing Memory Script Starting backup at 09-AUG-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output file name=/u01/app/oracle/dbs/snapcf_ora235.f tag=TAG20180809T235658 RECID=4 STAMP=983750219
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 09-AUG-18 Starting restore at 09-AUG-18
using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 09-AUG-18 contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script sql statement: alter database mount standby database contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oradata/ora235/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oradata/ora235/system01.dbf";
set newname for datafile 2 to
"/u01/app/oradata/ora235/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oradata/ora235/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oradata/ora235/users01.dbf";
set newname for datafile 5 to
"/data/oracle/data/lottu01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oradata/ora235/system01.dbf" datafile
2 auxiliary format
"/u01/app/oradata/ora235/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oradata/ora235/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oradata/ora235/users01.dbf" datafile
5 auxiliary format
"/data/oracle/data/lottu01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oradata/ora235/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 Starting backup at 09-AUG-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/data/oracle/data/lottu01.dbf
output file name=/data/oracle/data/lottu01.dbf tag=TAG20180809T235706
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:45
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oradata/ora235/system01.dbf
output file name=/u01/app/oradata/ora235/system01.dbf tag=TAG20180809T235706
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oradata/ora235/sysaux01.dbf
output file name=/u01/app/oradata/ora235/sysaux01.dbf tag=TAG20180809T235706
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/oradata/ora235/undotbs01.dbf
output file name=/u01/app/oradata/ora235/undotbs01.dbf tag=TAG20180809T235706
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=/u01/app/oradata/ora235/users01.dbf
output file name=/u01/app/oradata/ora235/users01.dbf tag=TAG20180809T235706
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 10-AUG-18 sql statement: alter system archive log current contents of Memory Script:
{
backup as copy reuse
archivelog like "/data/arch/1_3_983660602.dbf" auxiliary format
"/data/arch/1_3_983660602.dbf" ;
catalog clone archivelog "/data/arch/1_3_983660602.dbf";
switch clone datafile all;
}
executing Memory Script Starting backup at 10-AUG-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=3 RECID=19 STAMP=983750428
output file name=/data/arch/1_3_983660602.dbf RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 10-AUG-18 cataloged archived log
archived log file name=/data/arch/1_3_983660602.dbf RECID=1 STAMP=983750429 datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=983750429 file name=/u01/app/oradata/ora235/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=5 STAMP=983750429 file name=/u01/app/oradata/ora235/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=6 STAMP=983750429 file name=/u01/app/oradata/ora235/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=7 STAMP=983750429 file name=/u01/app/oradata/ora235/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=8 STAMP=983750429 file name=/data/oracle/data/lottu01.dbf contents of Memory Script:
{
set until scn 955597;
recover
standby
clone database
delete archivelog
;
}
executing Memory Script executing command: SET until clause Starting recover at 10-AUG-18
using channel ORA_AUX_DISK_1 starting media recovery archived log for thread 1 with sequence 3 is already on disk as file /data/arch/1_3_983660602.dbf
archived log file name=/data/arch/1_3_983660602.dbf thread=1 sequence=3
media recovery complete, elapsed time: 00:00:00
Finished recover at 10-AUG-18
Finished Duplicate Db at 10-AUG-18
2.9. 启用日志传送
在 Primary 端启动日志传送
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
2.10. 启用实时应用redo
在 Primary Database 产生的 Redo 日志;传送到 Standby Database;是通过 LGWR 或者 ARCH 进程完成。这个很好理解。默认情况下是由 ARCH 进程。有参数 *.LOG_ARCHIVE_DEST_2 控制的。使用 ARCH 进程; Primary Database 和 Standby Database 存在数据延迟。若 Primary Database 出现异常;容易造成部分数据丢失。为了避免数据丢失,必须要使用 LGWR 进程,需要用到 Standby Redolog。而LGWR 又分SYNC(同步)和ASYNC(异步)两种方式。
- SYNC方式:对网络要求比较高;必须等待写入本地日志文件操作和通过LNSn进程的网络传送都成功,Primary Database 上的事务才能提交成功。使用LGWR SYNC方式时,可以同时使用NET_TIMEOUT参数,这个参数单位是秒,代表如果多长时间内网络发送没有响应,LGWR 进程会抛出错误。因此对 Primary Database 性能有影响。
*.LOG_ARCHIVE_DEST_2='SERVICE=tns_standby LGWR SYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby NET_TIMEOUT = 30'
- ASYNC方式:采用异步方式;Primary Database 上的事务提交跟日志是否已经传送没有影响。
*.LOG_ARCHIVE_DEST_2='SERVICE=tns_standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby'
1. 在 Primary Database上执行;
alter system set log_archive_dest_2='SERVICE=tns_standby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_standby' scope=both;
2. 在Standby Database上执行;
alter system set log_archive_dest_2='SERVICE=tns_primary LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=db_primary' scope=both;
3. Standby Database启动实时应用redo
alter database recover managed standby database using current logfile ;
4. 验证结果
# 在Primary Database 上创建表t_lottu02
SQL> set SQLPROMPT Primary>
Primary>conn lottu/li0924
Connected.
Primary>create table t_lottu02 as select level id,'lottu' name from dual connect by level <= 3; Table created. # 在Standby Database上查看
SQL> set SQLPROMPT StandBy>
StandBy>conn lottu/li0924
Connected.
StandBy>select * from t_lottu02; ID NAME
---------- -----
1 lottu
2 lottu
3 lottu
9. Oracle DataGuard的介绍的更多相关文章
- Oracle Dataguard 介绍
Oracle DataGuard介绍 一. DataGuard的基本原理 当某次事务处理对生产数据库中的数据作出更改时,Oracle数据库将在一个联机重做日志文件里记录此次更改.在DataGuard中 ...
- Oracle DataGuard数据备份方案详解
Oracle DataGuard是一种数据库级别的HA方案,最主要功能是冗灾.数据保护.故障恢复等. 在生产数据库的"事务一致性"时,使用生产库的物理全备份(或物理COPY)创建备 ...
- Oracle dataguard 正常切换和应急切换
oracle dataguard提供异地容灾方案,能有效的防止单点故障和提供高可用技术,这里介绍dataguard正常主备切换和应急切换(应急切换模拟主库出现问题无法还原,备库脱离dataguard接 ...
- oracle dataguard主从切换
前言: 众所周知DataGuard一般的切换分成两种,一种是系统正常的情况下的切换这种方式为:switchover是无损切换,不会丢失数据:另外一种方式属于灾难情况下的切换,这种情况下一般主库已经启动 ...
- Oracle Dataguard之failover
Oracle Dataguard中,角色转换包含两类:Switchover和Failover.上文<Oracle Dataguard之switchover>中,我们已经谈过了switcho ...
- Oracle Dataguard之switchover
Oracle Dataguard的角色转换包含两类:Switchover和Failover.Switchover指主备之间角色转换,主库降为备库,备库升级为主库.而failover则是指主库出现问题时 ...
- Oracle Dataguard之Real-Time Apply
Oracle Dataguard一共支持三种模式:最大可用模式(Maximum Availability),最大性能模式(Maximum Performance),最大保护模式(Maximum Pro ...
- Oracle Dataguard之物理standby的基本配置
尽管网上有很多Oracle Dataguard的配置教程,但不难发现,很多采用的是rman duplicate这种方法,尽管此种方法较为简便.但在某种程度上,却也误导了初学者,虽说也能配置成功,但只知 ...
- Oracle优化器介绍
Oracle优化器介绍 本文讲述了Oracle优化器的概念.工作原理和使用方法,兼顾了Oracle8i.9i以及最新的10g三个版本.理解本文将有助于您更好的更有效的进行SQL优化工作. RBO优化器 ...
随机推荐
- linux上下载安装mysql,并使用
一:官网找mysql的安装包 可参考https://blog.csdn.net/a18852867035/article/details/81610611, 我是在https://dev.mysql. ...
- yii2 动态配置日志(log)
如果我们在项目中不允许修改配置文件中的 log 组件,那么动态配置 log 就变得很重要了,下面我分享一下动态配置 log 的方法: 默认的日志格式是 {date}{ip}{userID}{sessi ...
- python编码转换
Pyton内部的字符串一般都是unicode编码或字节字符串编码:代码中字符串的默认编码与代码文件本身的编码是一致的:编码转换通常需要以unicode编码作为中间编码进行转换,即先将其他编码的字符串解 ...
- idea其他人把jar更新之后更新不到
昨天下午开始就发现这个问题,其他同事把jar更新了之后,我一直获取不到更新之后的内容.尝试了很多方法,删除具体的更新不到的jar,一直不停的mvn clean install -U -Dmaven.t ...
- poj3061 Subsequence(尺取法)
https://vjudge.net/problem/POJ-3061 尺取发,s和t不断推进的算法.因为每一轮s都推进1所以复杂度为O(n) #include<iostream> #in ...
- 从注册表清理 IE10,IE11 用户代理字符串(UserAgent)中的垃圾信息
某一天,我发现我的 IE User Agent 字符串里面竟然含有刷机大师.百度浏览器等许多垃圾,国货流氓见怪不怪了. 微软自家的.NET CLR也占据了一大片,看着也不爽. 决定清理一下,但是却没找 ...
- 二进制小数及 IEEE 浮点表示
1.二进制小数 前面这篇博客 进制间的转换 我们已经讲过了各个进制数的表示.现在我们复习一下: 进位计数制的要素: ①.数码:用来表示进制数的元素.比如二进制数的数码为:0,1.十进制数的数码为:0 ...
- 使用Guava的RateLimiter完成简单的大流量限流
限流的一般思路: 1.随机丢弃一定规则的用户(迅速过滤掉90%的用户): 2.MQ削峰(比如设一个MQ可以容纳的最大消息量,达到这个量后MQ给予reject): 3.业务逻辑层使用RateLimite ...
- vue: 代码小记
1.事件派发:子控件->父控件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- Mac Node.js 配置
1.Node.js 简介 Node.js® 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,可方便地构建快速,可扩展的网络应用程序的平台.Node.js 使用事件驱动,非阻塞式 ...