Oracle Dataguard(主库为双节点集群)配置详解(3):配置主库

news/2025/1/13 2:10:32/

Oracle Dataguard(主库为双节点集群)配置详解(3):配置主库

目录

  • Oracle Dataguard(主库为双节点集群)配置详解(3):配置主库
    • 一、开启归档
    • 二、开启强制日志
    • 三、添加 standby 日志
        • 1、查看主库的日志信息
        • 2、添加 standby log
        • 3、重新查看日志信息
    • 四、配置静态监听
        • 1、配置 listener.ora 文件
        • 2、配置 tnsnames.ora 文件
        • 3、测试连接
    • 五、修改主库的初始化参数
        • 1、根据 spfile 生成 pfile 文件
        • 2、修改 pfile 文件的内容如下
        • 3、重启数据库到 nomount,根据修改后的 pfile 文件重新生成 spfile 参数文件
        • 4、重新启动数据库(两个节点同时操作)
    • 六、复制主库密码文件至备库

一、开启归档

-- 查看主库归档状态
SQL> archive log list;
Database log mode	       No Archive Mode
Automatic archival	       Disabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     4
Current log sequence	       5-- 停库
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.-- 启动数据库到mount状态
SQL> startup mount;
ORACLE instance started.Total System Global Area  626327552 bytes
Fixed Size		    2255832 bytes
Variable Size		  297796648 bytes
Database Buffers	  322961408 bytes
Redo Buffers		    3313664 bytes
Database mounted.-- 修改数据库为归档模式
SQL> alter database archivelog;Database altered.-- 打开数据库
SQL> alter database open;Database altered.-- 查看归档状态
SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     4
Next log sequence to archive   5
Current log sequence	       5

二、开启强制日志

SQL> alter database force logging;Database altered.

三、添加 standby 日志

创建主库的standby日志文件,每个实例的组数要比logfile多一组。

1、查看主库的日志信息
-- 查看日志组
select * from v$log;-- 查看日志文件
select member from v$logfile;SQL> select * from v$log;GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE	  MEMBERS ARC STATUS	 FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1	    1	      11  104857600	   512		2 NO  CURRENT		      986498 09-JAN-25	 2.8147E+142	    1	       0  104857600	   512		2 YES UNUSED			   0			  03	    1	       0  104857600	   512		2 YES UNUSED			   0			  04	    2	       9  104857600	   512		2 NO  CURRENT		      986588 09-JAN-25	 2.8147E+145	    2	       0  104857600	   512		2 YES UNUSED			   0			  06	    2	       0  104857600	   512		2 YES UNUSED			   0			  06 rows selected.SQL> select member from v$logfile;MEMBER
------------------------------------------------------------------------
+DATA/hisdb/onlinelog/group_1.266.1189965499
+BAK/hisdb/onlinelog/group_1.260.1189965507
+DATA/hisdb/onlinelog/group_2.265.1189965519
+BAK/hisdb/onlinelog/group_2.259.1189965527
+DATA/hisdb/onlinelog/group_3.262.1189965537
+BAK/hisdb/onlinelog/group_3.275.1189965547
+DATA/hisdb/onlinelog/group_4.261.1189965557
+BAK/hisdb/onlinelog/group_4.276.1189965567
+DATA/hisdb/onlinelog/group_5.272.1189965577
+BAK/hisdb/onlinelog/group_5.277.1189965587
+DATA/hisdb/onlinelog/group_6.273.1189965595
+BAK/hisdb/onlinelog/group_6.278.118996560312 rows selected.
2、添加 standby log

添加standby log必须和redo log大小一样,数量为:standby logfile=(1+logfile组数)*thread=(1+3)*2=8

alter database add standby logfile thread 1 group 11 size 100m;
alter database add standby logfile thread 1 group 12 size 100m;
alter database add standby logfile thread 1 group 13 size 100m;
alter database add standby logfile thread 1 group 14 size 100m;
alter database add standby logfile thread 2 group 15 size 100m;
alter database add standby logfile thread 2 group 16 size 100m;
alter database add standby logfile thread 2 group 17 size 100m;
alter database add standby logfile thread 2 group 18 size 100m;
3、重新查看日志信息
SQL> select * from v$log;GROUP#    THREAD#  SEQUENCE#      BYTES  BLOCKSIZE	  MEMBERS ARC STATUS	       FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME
---------- ---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- --------- ------------ ---------1	    1	      11  104857600	   512		2 NO  CURRENT		      986498 09-JAN-25	 2.8147E+142	    1	       0  104857600	   512		2 YES UNUSED			   0			  03	    1	       0  104857600	   512		2 YES UNUSED			   0			  04	    2	       9  104857600	   512		2 NO  CURRENT		      986588 09-JAN-25	 2.8147E+145	    2	       0  104857600	   512		2 YES UNUSED			   0			  06	    2	       0  104857600	   512		2 YES UNUSED			   0			  06 rows selected.SQL> select * from v$Standby_log;GROUP# DBID 				       THREAD#	SEQUENCE#      BYTES  BLOCKSIZE       USED ARC STATUS	  FIRST_CHANGE# FIRST_TIM NEXT_CHANGE# NEXT_TIME LAS
T_CHANGE# LAST_TIME---------- ---------------------------------------- ---------- ---------------	
11 UNASSIGNED					     1		0  104857600	    512 	 0 YES UNASSIGNED12 UNASSIGNED					     1		0  104857600	    512 	 0 YES UNASSIGNED13 UNASSIGNED					     1		0  104857600	    512 	 0 YES UNASSIGNED14 UNASSIGNED					     1		0  104857600	    512 	 0 YES UNASSIGNED15 UNASSIGNED					     2		0  104857600	    512 	 0 YES UNASSIGNED16 UNASSIGNED					     2		0  104857600	    512 	 0 YES UNASSIGNED17 UNASSIGNED					     2		0  104857600	    512 	 0 YES UNASSIGNED18 UNASSIGNED					     2		0  104857600	    512 	 0 YES UNASSIGNED8 rows selected.SQL> select member from v$logfile;MEMBER
----------------------------------------------------------------------
+DATA/hisdb/onlinelog/group_1.266.1189965499
+BAK/hisdb/onlinelog/group_1.260.1189965507
+DATA/hisdb/onlinelog/group_2.265.1189965519
+BAK/hisdb/onlinelog/group_2.259.1189965527
+DATA/hisdb/onlinelog/group_3.262.1189965537
+BAK/hisdb/onlinelog/group_3.275.1189965547
+DATA/hisdb/onlinelog/group_4.261.1189965557
+BAK/hisdb/onlinelog/group_4.276.1189965567
+DATA/hisdb/onlinelog/group_11.271.1189966083
+BAK/hisdb/onlinelog/group_11.266.1189966091
+DATA/hisdb/onlinelog/group_12.270.1189966101
+BAK/hisdb/onlinelog/group_12.265.1189966111
+DATA/hisdb/onlinelog/group_13.269.1189966121
+BAK/hisdb/onlinelog/group_13.263.1189966129
+DATA/hisdb/onlinelog/group_14.268.1189966139
+BAK/hisdb/onlinelog/group_14.262.1189966147
+DATA/hisdb/onlinelog/group_5.272.1189965577
+BAK/hisdb/onlinelog/group_5.277.1189965587
+DATA/hisdb/onlinelog/group_6.273.1189965595
+BAK/hisdb/onlinelog/group_6.278.1189965603
+DATA/hisdb/onlinelog/group_15.274.1189966155
+BAK/hisdb/onlinelog/group_15.281.1189966167
+DATA/hisdb/onlinelog/group_16.275.1189966175
+BAK/hisdb/onlinelog/group_16.282.1189966183
+DATA/hisdb/onlinelog/group_17.276.1189966193
+BAK/hisdb/onlinelog/group_17.283.1189966201
+DATA/hisdb/onlinelog/group_18.277.1189966209
+BAK/hisdb/onlinelog/group_18.284.118996621528 rows selected.

四、配置静态监听

1、配置 listener.ora 文件

切换到grid用户,在$ORACLE_HOME/network/admin/listener.ora文件中添加如下内容:

,GLOBAL_DBNAME配置为db_unique_name,SID_NAME配置为该节点ORACLE_SID

[grid@rac01 ~]$ cd $ORACLE_HOME/network/admin[grid@rac01 admin]$ ls
endpoints_listener.ora  listener2501091PM3305.bak  listener.ora  listener.ora.bak.rac01  samples  shrept.lst  sqlnet.ora# 节点1
[grid@rac01 admin]$ vi listener.oraSID_LIST_LISTENER =(SID_LIST =(SID_DESC = (GLOBAL_DBNAME = hisdb)(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)(SID_NAME = his1)))# 节点2
SID_LIST_LISTENER =(SID_LIST =(SID_DESC = (GLOBAL_DBNAME = hisdb)(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)(SID_NAME = his2)))

配置完成后使用如下命令重启监听:

lsnrctl stop
lsnrctl start
2、配置 tnsnames.ora 文件

切换到 oracle用户,在$ORACLE_HOME/network/admin/tnsnames.ora文件中添加如下内容。

[oracle@rac01 ~]$ cd $ORACLE_HOME/network/admin[oracle@rac01 admin]$ ls
samples  shrept.lst  tnsnames.ora# 节点1与节点2都需要配置,且内容相同
# 其中 hisdb、hisdb1、hisdb2 的 host 配置分别为 rac-scan、节点1与节点2的IP地址,service_name配置为listener.ora文件中的GLOBAL_DBNAME也就是主库的db_unique_name
# hisdbdg 的 service_name 为备库 db_unique_name
[grid@rac01 admin]$ vi tnsnames.orahisdb =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = hisdb)))hisdb1 =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.101)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = hisdb)(SID = his1)))hisdb2 =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.102)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = hisdb)(SID = his2)))dghisdb =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.5)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = hisdbdg)))
3、测试连接
tnsping hisdb
tnsping hisdb1
tnsping hisdb2
tnsping hisdbdg

五、修改主库的初始化参数

在节点1执行如下操作:

1、根据 spfile 生成 pfile 文件
SQL> create pfile='/home/oracle/inithis.ora' from spfile;File created.
2、修改 pfile 文件的内容如下
[oracle@rac01 ~]$ vi /home/oracle/inithis.orahis2.__db_cache_size=385875968
his1.__db_cache_size=369098752
his1.__java_pool_size=4194304
his2.__java_pool_size=4194304
his1.__large_pool_size=8388608
his2.__large_pool_size=8388608
his1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
his2.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
his1.__pga_aggregate_target=209715200
his2.__pga_aggregate_target=209715200
his1.__sga_target=629145600
his2.__sga_target=629145600
his1.__shared_io_pool_size=0
his2.__shared_io_pool_size=0
his2.__shared_pool_size=222298112
his1.__shared_pool_size=239075328
his1.__streams_pool_size=0
his2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/hisdb/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATA/hisdb/controlfile/current.260.1189953459','+BAK/hisdb/controlfile/current.256.1189953459'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='hisdb'
*.db_recovery_file_dest='+BAK'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=hisXDB)'
his2.instance_number=2
his1.instance_number=1
*.open_cursors=300
*.pga_aggregate_target=209715200
*.processes=150
*.remote_listener='rac-scan:1521'
*.remote_login_passwordfile='exclusive'
*.sga_target=629145600
his2.thread=2
his1.thread=1
his1.undo_tablespace='UNDOTBS1'
his2.undo_tablespace='UNDOTBS2'# 在参数文件中添加以下内容:
*.db_unique_name='hisdb'                           # 主数据库的唯一名,默认和数据库名一致
*.log_archive_config='dg_config=(hisdb,hisdbdg)'   # 主库和备库在tnsname.ora中的连接名*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hisdb'                             # 主数据库的唯一名
*.log_archive_dest_2='service=hisdbdg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=hisdbdg'                           # 备用数据库的唯一名
*.db_file_name_convert='/usr/local/oradata/hisdbdg/','+DATA/hisdb/datafile/'
# 格式: 
# 主库配置格式: *.db_file_name_convert= 备用数据库数据文件目录,主数据库数据文件目录
# 备库配置格式: *.db_file_name_convert= 主数据库数据文件目录,备用数据库数据文件目录
*.log_file_name_convert='/usr/local/oradata/hisdbdg/','+DATA/hisdb/onlinelog/'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.standby_file_management='auto'
# fal_client用于接受日志,fal_server用于发送日志。
# 也即无论是主库或备库,fal_server=对方,fal_client=自己
# 主库设置如下
*.fal_server='hisdbdg'
*.fal_client='hisdb'
# 备库设置如下
# *.fal_server='hisdb'
# *.fal_client='hisdbdg'
3、重启数据库到 nomount,根据修改后的 pfile 文件重新生成 spfile 参数文件
-- 在节点1和节点2上关闭数据库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.-- 使用修改后的参数文件启动数据库到nomount
SQL> startup nomount pfile='/home/oracle/inithis.ora'
ORACLE instance started.Total System Global Area  626327552 bytes
Fixed Size		    2255832 bytes
Variable Size		  297796648 bytes
Database Buffers	  322961408 bytes
Redo Buffers		    3313664 bytes-- 根据修改后的 pfile 文件重新生成 spfile 参数文件
SQL> create spfile='+DATA/hisdb/spfilehis.ora' from pfile='/home/oracle/inithis.ora';File created.
4、重新启动数据库(两个节点同时操作)
SQL> shutdown immediate
ORA-01507: database not mountedORACLE instance shut down.
SQL> startup
ORACLE instance started.Total System Global Area  626327552 bytes
Fixed Size		    2255832 bytes
Variable Size		  297796648 bytes
Database Buffers	  322961408 bytes
Redo Buffers		    3313664 bytes
Database mounted.
Database opened.

六、复制主库密码文件至备库

备库修改密码文件名为orapwhisdg,备库的实例名为hisdg

[oracle@rac01 dbs]$ scp orapwhis1 oracle@racdg:/usr/local/oracle/product/11.2.0/db_1/dbs/orapwhisdg
oracle@racdg's password:     100% 1536     1.5KB/s   00:00 # 在备库查看密码文件
[oracle@racdg dbs]$ pwd
/usr/local/oracle/product/11.2.0/db_1/dbs
[oracle@racdg dbs]$ ll
总用量 8
-rw-r--r--. 1 oracle oinstall 2851 515 2009 init.ora
-rw-r-----  1 oracle oinstall 1536 110 14:57 orapwhisdg

http://www.ppmy.cn/news/1562675.html

相关文章

React 元素渲染

React 元素渲染 React 是一个用于构建用户界面的 JavaScript 库,它允许开发人员创建大型应用程序,这些应用程序可以随着时间的推移而高效地更新和渲染。React 的核心概念之一是元素渲染,它描述了如何将 JavaScript 对象转换为 DOM&#xff0…

工作效率提升:使用Anaconda Prompt 创建虚拟环境总结

目录 完整顺序命令流程(直接照着改就行)详细步骤解析(想要详细解析的看过来)1. 创建一个用于存储 Conda 环境的目录(可选)2. 创建新的 Conda 虚拟环境并指定路径3. 激活新创建的环境4. 安装 Jupyter Notebo…

Unity3d 基于Barracuda推理库和YOLO算法实现对象检测功能

前言 近年来,随着AI技术的发展,在游戏引擎中实现和运行机器学习模型的需求也逐渐显现。Unity3d引擎官方推出深度学习推理框架–Barracuda ,旨在帮助开发者在Unity3d中轻松地实现和运行机器学习模型,它的主要功能是支持在 Unity 中…

Vue.js组件开发-使用EventBus实现组件间高效通信

在Vue.js中,EventBus是一种用于组件间通信的方式,特别是在没有父子关系的组件之间。我们可以创建一个空的Vue实例来作为事件总线。 实例: 展示如何使用EventBus实现两个兄弟组件之间的通信。 首先,我们需要创建一个EventBus&am…

使用正则表达式读取文本数据【Python】

使用正则表达式读取文本数据 假如我们需要处理的数据具有很强的规律性, 例如下面这样, 数据基本上都是一个独立的一行, 并且每个数据都有名称标志. RUN OU 1.903784OV 1.862293OW 1.860681OUINV 548.000793STOP index 1V 0.000000W 0.000000E_theta 0.000000UINV 0.…

WebRtc04: JavaScript知识回顾

JavaScirpt调试方法 基础知识 变量与类型 基本运算 if/else for循环 函数 日志打印 console.log("xxx")

机器学习之留出法中的分层采样和多次切分

留出法(Hold-out Method) 本身是数据划分的一种方式,将数据集分为训练集和测试集。为了提升留出法的评估效果,常常结合分层采样和多次切分等技术。以下是详细说明这些方法如何增强留出法的效果。 1. 留出法(Hold-out Method) 留出法是将数据集划分为训练集和测试集的一…

HTML5 加载动画(Loading Animation)

加载动画(Loading Animation)详解 概述 加载动画是指在数据加载过程中,向用户展示的一种视觉效果,旨在提升用户体验,告知用户系统正在处理请求。它可以减少用户的等待焦虑感,提高界面的互动性。 常见的加…