Oracle Dataguard(主库为双节点集群)配置详解(5):将主库复制到备库并启动同步

ops/2025/1/14 2:38:30/

Oracle Dataguard(主库为双节点集群)配置详解(5):将主库复制到备库并启动同步

目录

  • Oracle Dataguard(主库为双节点集群)配置详解(5):将主库复制到备库并启动同步
    • 一、使用 rman 连接主库和备库,并设置好主备关系
    • 二、执行复制命令
    • 三、启动备库
        • 1、查看备库的状态
        • 2、正常启动备库
        • 3、开启实时同步
        • 4、查看备库状态
        • 5、查看备库进程
        • 6、查看主库状态
        • 7、查看主库进程
    • 四、实时同步验证

一、使用 rman 连接主库和备库,并设置好主备关系

target——主库:auxiliary——备库。

在主库的节点1执行如下命令:

[oracle@rac01 ~]$ rman target sys/oracle@hisdb1 auxiliary sys/oracle@hisdbdgRecovery Manager: Release 11.2.0.4.0 - Production on Sat Jan 11 11:45:08 2025Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.connected to target database: HISDB (DBID=2102569523)
connected to auxiliary database: HISDB (not mounted)

二、执行复制命令

该命令可以直接恢复数据文件、standby日志文件和控制文件。

RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE;  Starting Duplicate Db at 11-JAN-25
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISKcontents of Memory Script:
{backup as copy reusetargetfile  '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwhis1' auxiliary format '/usr/local/oracle/product/11.2.0/db_1/dbs/orapwhisdg'   ;
}
executing Memory ScriptStarting backup at 11-JAN-25
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 instance=his1 device type=DISK
Finished backup at 11-JAN-25contents of Memory Script:
{backup as copy current controlfile for standby auxiliary format  '/usr/local/oradata/hisdbdg/control01.ctl';restore clone controlfile to  '/usr/local/oracle/fast_recovery_area/hisdbdg/control02.ctl' from '/usr/local/oradata/hisdbdg/control01.ctl';
}
executing Memory ScriptStarting backup at 11-JAN-25
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/db_1/dbs/snapcf_his1.f tag=TAG20250111T124752 RECID=3 STAMP=1190119677
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 11-JAN-25Starting restore at 11-JAN-25
using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 11-JAN-25contents 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 "/usr/local/oradata/hisdbdg/temp.263.1189953499";switch clone tempfile all;set newname for datafile  1 to "/usr/local/oradata/hisdbdg/system.256.1189953387";set newname for datafile  2 to "/usr/local/oradata/hisdbdg/sysaux.257.1189953387";set newname for datafile  3 to "/usr/local/oradata/hisdbdg/undotbs1.258.1189953387";set newname for datafile  4 to "/usr/local/oradata/hisdbdg/users.259.1189953387";set newname for datafile  5 to "/usr/local/oradata/hisdbdg/undotbs2.264.1189953701";backup as copy reusedatafile  1 auxiliary format "/usr/local/oradata/hisdbdg/system.256.1189953387"   datafile 2 auxiliary format "/usr/local/oradata/hisdbdg/sysaux.257.1189953387"   datafile 3 auxiliary format "/usr/local/oradata/hisdbdg/undotbs1.258.1189953387"   datafile 4 auxiliary format "/usr/local/oradata/hisdbdg/users.259.1189953387"   datafile 5 auxiliary format "/usr/local/oradata/hisdbdg/undotbs2.264.1189953701"   ;sql 'alter system archive log current';
}
executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /usr/local/oradata/hisdbdg/temp.263.1189953499 in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 11-JAN-25
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=+DATA/hisdb/datafile/system.256.1189953387
output file name=/usr/local/oradata/hisdbdg/system.256.1189953387 tag=TAG20250111T124809
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=+DATA/hisdb/datafile/sysaux.257.1189953387
output file name=/usr/local/oradata/hisdbdg/sysaux.257.1189953387 tag=TAG20250111T124809
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=+DATA/hisdb/datafile/undotbs1.258.1189953387
output file name=/usr/local/oradata/hisdbdg/undotbs1.258.1189953387 tag=TAG20250111T124809
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=+DATA/hisdb/datafile/undotbs2.264.1189953701
output file name=/usr/local/oradata/hisdbdg/undotbs2.264.1189953701 tag=TAG20250111T124809
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=+DATA/hisdb/datafile/users.259.1189953387
output file name=/usr/local/oradata/hisdbdg/users.259.1189953387 tag=TAG20250111T124809
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 11-JAN-25sql 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=3 STAMP=1190119881 file name=/usr/local/oradata/hisdbdg/system.256.1189953387
datafile 2 switched to datafile copy
input datafile copy RECID=4 STAMP=1190119881 file name=/usr/local/oradata/hisdbdg/sysaux.257.1189953387
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=1190119881 file name=/usr/local/oradata/hisdbdg/undotbs1.258.1189953387
datafile 4 switched to datafile copy
input datafile copy RECID=6 STAMP=1190119881 file name=/usr/local/oradata/hisdbdg/users.259.1189953387
datafile 5 switched to datafile copy
input datafile copy RECID=7 STAMP=1190119881 file name=/usr/local/oradata/hisdbdg/undotbs2.264.1189953701
Finished Duplicate Db at 11-JAN-25

三、启动备库

1、查看备库的状态

执行完同步后,数据库状态会从 nomount --> mount

SQL> select open_mode from v$database;OPEN_MODE
--------------------
MOUNTED
2、正常启动备库
SQL> alter database open;Database altered.
3、开启实时同步
SQL> alter database recover managed standby database using current logfile disconnect from session;Database altered.
4、查看备库状态
SQL> select open_mode,log_mode,open_mode ,database_role from v$database;OPEN_MODE	     LOG_MODE	  OPEN_MODE	       DATABASE_ROLE
-------------------- ------------ -------------------- ----------------
READ ONLY WITH APPLY ARCHIVELOG   READ ONLY WITH APPLY PHYSICAL STANDBY
5、查看备库进程
SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby;PROCESS   STATUS	  THREAD#  SEQUENCE#	 BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CLOSING		2	  20	  10240       1912
ARCH	  CLOSING		1	  24	  32768        265
RFS	  IDLE			0	   0	      0 	 0
RFS	  IDLE			0	   0	      0 	 0
RFS	  WRITING		2	  21	    144 	 1
RFS	  WRITING		1	  25	    103 	 1
RFS	  IDLE			0	   0	      0 	 0
RFS	  IDLE			0	   0	      0 	 0
MRP0	  APPLYING_LOG		2	  20	   2418      1215111 rows selected.
6、查看主库状态
SQL> select open_mode,log_mode,open_mode ,database_role from v$database;OPEN_MODE	     LOG_MODE	  OPEN_MODE	       DATABASE_ROLE
-------------------- ------------ -------------------- ----------------
READ WRITE	     ARCHIVELOG   READ WRITE	       PRIMARY
7、查看主库进程
SQL> select process, status, thread#,sequence#, block#, blocks from v$managed_standby;PROCESS   STATUS	  THREAD#  SEQUENCE#	 BLOCK#     BLOCKS
--------- ------------ ---------- ---------- ---------- ----------
ARCH	  CLOSING		1	  24	  32768        265
ARCH	  CLOSING		1	  23	  47104       1418
ARCH	  CONNECTED		0	   0	      0 	 0
ARCH	  CLOSING		1	  24	  32769        264
LNS	  WRITING		1	  25	    151 	 1

四、实时同步验证

1、在主库创建 t1 表插入以下数据

SQL> 
create table t1(id int primary key,name varchar2(20));
insert into t1 values(1,'mark');
insert into t1 values(2,'jack');
commit;Table created.SQL> 
1 row created.SQL> 
1 row created.SQL> 
Commit complete.

2、在备库查询 t1 表中的数据

SQL> select * from t1;ID NAME
---------- --------------------1 mark2 jack

http://www.ppmy.cn/ops/149887.html

相关文章

【MySQL基础篇】十三、用户与权限管理

文章目录 Ⅰ. 认识用户管理1、概念2、mysql 中的用户信息 Ⅱ. 用户的操作1、创建用户2、删除用户3、修改密码举例 Ⅱ. 刷新指令 -- flush privilegesⅢ. 认识权限管理1、概念2、MySQL权限信息以及权限表3、MySQL授权规则4、MySQL权限检查机制 Ⅳ. 权限的操作1、查看用户现有权限…

NGINX 支持 UDP 协议

随着现代网络应用日益复杂,传统的 HTTP 协议逐渐无法满足某些实时性要求较高的场景。在这种背景下,UDP(用户数据报协议)成为了许多实时通信、视频流和在线游戏的首选协议。近年来,NGINX 作为广泛使用的高性能 Web 服务…

探秘MetaGPT:革新软件开发的多智能体框架(22/30)

一、MetaGPT 引发的 AI 变革浪潮 近年来,人工智能大模型领域取得了令人瞩目的进展,GPT-3、GPT-4、PaLM 等模型展现出了惊人的自然语言处理能力,仿佛为 AI 世界打开了一扇通往无限可能的大门。它们能够生成流畅的文本、回答复杂的问题、进行创…

(java) String 字符串

前言: 本篇内容不多,单独介绍java中的字符串String,介绍了字符串的存储原理(辅助理解),以及其主要使用的方法,同时也介绍了StringBuilder可变字符序列 1. String 字符串 字符串一旦创建&#…

后端技术选型 sa-token校验学习 中 文档学习

目录 依赖 配置文件 登录验证 登录与注销 Cookie 自动注入 前后端分离(无 Cookie 模式) 何为 Cookie 何为无 Cookie 模式? 解决方案 1、后端将 token 返回到前端 2、前端将 token 提交到后端 其它解决方案? 自定义 Token 前缀 [ 记住我 ] 模式 前后端…

MySQL视图笔记

视图的理解 ①视图是一种 虚拟表 ,本身是 不具有数据 的,占用很少的内存空间,它是 SQL 中的一个重要概念。 ②视图建立在已有表的基础上, 视图赖以建立的这些表称为基表。 ③对视图中的数据进行增加删除和修改,对应的数据表&a…

【HTML+CSS+JS+VUE】web前端教程-21-字体属性

字体属性 css字体属性定义字体,颜色、大小、加粗、文字样式 color 规定文本的颜色 color: red;color: #ff0000;color: rgb(255,0,0);color: rgba(255,0,0,.5);font-size 设置文本的大小 能否管理文字的大小,在网页设计中是非常重要的,但是,你不能通过调整字体大小使段落看…

对React中类组件和函数组件的理解?有什么区别?

React 中类组件和函数组件的理解与区别 React 中有两种主要的组件类型:类组件(Class Component)和函数组件(Function Component)。两者有许多相似之处,但也有一些显著的区别。在 React 16.8 引入了 Hooks …