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

server/2025/1/15 4:08:40/

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/server/158456.html

相关文章

深入理解 Java 设计模式之策略模式

一、引言 在 Java 编程的世界里,设计模式就如同建筑师手中的蓝图,能够帮助我们构建出更加健壮、灵活且易于维护的代码结构。而策略模式作为一种经典的行为型设计模式,在诸多实际开发场景中都发挥着至关重要的作用。它能够让算法的定义与使用…

wsl2上mysql出现ip端口冲突问题

现象出现于win11系统wsl2平台跑ubuntu,在win11 22h2之后提供固化wsl ip地址的功能,具体可以百度,大概是在C:/用户/用户名文件夹下新建.wslconfig文件,其中添加固化IP地址的参数。 固化完毕后,wsl将不再使用虚拟ip&…

Eureka缓存机制

一、Eureka的CAP特性 Eureka是一个AP系统,它优先保证可用性(A)和分区容错性(P),而不保证强一致性(C)。这种设计使得Eureka在分布式系统中能够应对各种故障和分区情况,保…

Java 原型模式、建造者模式、单例模式

原型模式、建造者模式 原型模式 原型模式(Prototype Pattern)是一种创建型设计模式,它允许你通过复制现有对象来创建新对象,而不是通过实例化类。这种模式在需要大量相似对象时非常有用,因为它可以减少创建对象的开销…

(leetcode算法题)155. 最小栈 901. 股票价格跨度

这两道题都是单调栈专题中的引子题目, 如果我们仔细分析题目,如果只是想得到当前历史数据中最小值和可以发现这两道题, 都不用使用一个额外的容器装以往所有的历史数据才能得到结果 对于155来说, 只需要维护最小栈就可以快速获…

数据结构与算法之二叉树: LeetCode 701. 二叉搜索树中的插入操作 (Ts版)

二叉搜索树中的插入操作 https://leetcode.cn/problems/insert-into-a-binary-search-tree/description/ 描述 给定二叉搜索树(BST)的根节点 root 和要插入树中的值 value ,将值插入二叉搜索树返回插入后二叉搜索树的根节点。 输入数据 保…

第六章:网页设计

文章目录: 一:网页设计 1.基本概念 1.1 网页 1.2 网站 1.3 工具 2.HTML语言 2.1 基础 2.2 标记 2.2.1 结构 2.2.2 文本 2.2.3 功能 2.2.4 表单 2.3 属性 二:IIS 1.定义 2.主要功能 3.特点与优势 4.应用场景 4.1 安装IIS …

SQL进阶实战技巧:统计相同时刻多地登陆的用户?

目录 0 问题描述 1 数据准备 2 代码实现 3 问题拓展 3.1 查询每个用户登录日期的最大空档期