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

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

目录

一、为备库配置静态监听

1、配置 listener.ora 文件
shell 复制代码
[oracle@racdg admin]$ vi listener.ora 

# listener.ora Network Configuration File: /usr/local/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = racdg)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /usr/local/oracle


SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
     (GLOBAL_DBNAME = hisdbdg)
     (ORACLE_HOME = /usr/local/oracle/product/11.2.0/db_1)
     (SID_NAME = hisdg)
    )
2、重启监听、查看监听状态
shell 复制代码
[oracle@racdg admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-JAN-2025 15:14:59

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /usr/local/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /usr/local/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /usr/local/oracle/diag/tnslsnr/racdg/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=racdg)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                10-JAN-2025 15:14:59
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /usr/local/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /usr/local/oracle/diag/tnslsnr/racdg/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=racdg)(PORT=1521)))
Services Summary...
Service "hisdbdg" has 1 instance(s).
  Instance "hisdg", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
3、配置 tnsnames

备库的tnsnames文件配置内容与主库相同。

shell 复制代码
[oracle@racdg dbs]$ vi tnsnames.ora 

hisdb =
  (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)
    )
  )
4、测试连接
shell 复制代码
[oracle@rac02 admin]$ tnsping hisdb

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-JAN-2025 18:55:14

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hisdb)))
OK (0 msec)

[oracle@rac02 admin]$ tnsping hisdb1

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-JAN-2025 18:55:17

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.101)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hisdb) (SID = his1)
))OK (0 msec)

[oracle@rac02 admin]$ tnsping hisdb2

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-JAN-2025 18:55:19

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.102)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hisdb) (SID = his2)
))OK (0 msec)


[oracle@rac02 admin]$ tnsping hisdbdg

TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 10-JAN-2025 18:55:21

Copyright (c) 1997, 2013, Oracle.  All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.5)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = hisdbdg)))
OK (0 msec)

二、创建备库的 pfile 文件

1、在主库创建 pfile 文件并复制至备库

(1)在主库创建pfile文件

sql 复制代码
SQL> create pfile='/home/oracle/inithisdg.ora' from spfile;

File created.

(2)把初始化参数文件复制到备库的$ORACLE_HOME/dbs目录

shell 复制代码
[oracle@rac01 ~]$ pwd
/home/oracle

[oracle@rac01 ~]$ ll
total 2487208
drwxr-xr-x 7 oracle oinstall        136 Aug 27  2013 database
-rw-r--r-- 1 oracle asmadmin       2021 Jan 11 10:37 inithisdg.ora
-rw-r--r-- 1 oracle asmadmin       2020 Jan 10 14:13 inithis.ora
-rw-r--r-- 1 oracle oinstall 1395582860 Jan  7  2020 p13390677_112040_Linux-x86-64_1of7.zip
-rw-r--r-- 1 oracle oinstall 1151304589 Jan  7  2020 p13390677_112040_Linux-x86-64_2of7.zip

[oracle@rac01 ~]$ scp inithisdg.ora oracle@racdg:/usr/local/oracle/product/11.2.0/db_1/dbs
oracle@racdg's password: 
inithisdg.ora                        100% 2021     2.0KB/s   00:00    
2、修改备库的初始化参数文件

在主库的参数文件基础上进行修改,内容如下:

shell 复制代码
[oracle@racdg dbs]$ pwd
/usr/local/oracle/product/11.2.0/db_1/dbs
[oracle@racdg dbs]$ ll
总用量 16
-rw-r--r--  1 oracle oinstall 2021 1月  11 10:41 inithisdg.ora
-rw-r--r--. 1 oracle oinstall 2851 5月  15 2009 init.ora
-rw-r-----  1 oracle oinstall 1536 1月  10 14:57 orapwhisdg
-rw-r-----  1 oracle oinstall  914 1月  10 15:21 tnsnames.ora

[oracle@rac11gstd dbs]$ vi inithisdg.ora
*.__db_cache_size=385875968
*.__java_pool_size=4194304
*.__large_pool_size=8388608
*.__oracle_base='/usr/local/oracle' #ORACLE_BASE set from environment
*.__pga_aggregate_target=209715200
*.__sga_target=629145600
*.__shared_io_pool_size=0
*.__shared_pool_size=222298112
*.__streams_pool_size=0
*.audit_file_dest='/usr/local/oracle/admin/hisdbdg/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/usr/local/oradata/hisdbdg/control01.ctl','/usr/local/oracle/fast_recovery_area/hisdbdg/control02.ctl'
*.db_block_size=8192
*.db_create_file_dest='/usr/local/oracle'
*.db_domain=''
*.db_file_name_convert='+DATA/hisdb/datafile/','/usr/local/oradata/hisdbdg/'
*.db_file_name_convert='+DATA/hisdb/tempfile/','/usr/local/oradata/hisdbdg/'
*.log_file_name_convert='+DATA/hisdb/onlinelog/','/usr/local/oradata/hisdbdg/'
*.db_name='hisdb'
*.db_unique_name='hisdbdg'
*.db_recovery_file_dest='/usr/local/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/usr/local/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=hisdbXDB)'
*.fal_client='hisdbdg'
*.fal_server='hisdb'
*.log_archive_config='dg_config=(hisdbdg,hisdb)'
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hisdbdg'
*.log_archive_dest_2='service=hisdbdg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=hisdb'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.open_cursors=300
*.pga_aggregate_target=209715200
*.processes=150
*.remote_login_passwordfile='exclusive'
*.sga_target=629145600
*.standby_file_management='auto'
*.undo_tablespace='UNDOTBS1'

三、创建参数文件中涉及到的目录并启动数据库到nomount

1、创建目录
shell 复制代码
# 要创建的目录如下:
mkdir -p /usr/local/oracle/admin/hisdbdg/adump
mkdir -p /usr/local/oracle/fast_recovery_area/hisdbdg
mkdir -p /usr/local/oradata/hisdbdg/

[oracle@racdg dbs]$ mkdir -p /usr/local/oracle/admin/hisdbdg/adump
[oracle@racdg dbs]$ mkdir -p /usr/local/oracle/fast_recovery_area/hisdbdg
[oracle@racdg dbs]$ mkdir -p /usr/local/oradata/hisdbdg/
2、启动备库到 nomount
sql 复制代码
-- 使用修改后的 pfile 文件启动备库到 nomount
SQL> startup nomount pfile='$ORACLE_HOME/dbs/inithisdg.ora';
ORACLE instance started.

Total System Global Area  626327552 bytes
Fixed Size		    2255832 bytes
Variable Size		  234882088 bytes
Database Buffers	  385875968 bytes
Redo Buffers		    3313664 bytes

-- 查看备库的 db_unique_name
SQL> show parameter db_unique_name

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_unique_name			     string	 hisdbdg

-- 生成 spfile 文件
SQL> create spfile from pfile='$ORACLE_HOME/dbs/inithisdg.ora';

File created.
相关推荐
java1234_小锋1 小时前
Redis有哪些常用应用场景?
java·数据库·redis
@逆风微笑代码狗1 小时前
144.《在 macOS 上安装 Redis》
数据库·redis·macos
大霸王龙1 小时前
Apache AGE:基于PostgreSQL的图数据库深度解析
数据库·postgresql·apache
前端 贾公子2 小时前
MySQL数据库基础 === 多表查询
数据库
大雄野比2 小时前
Mysql连接报错排查解决记录
数据库·mysql·adb
Run Out Of Brain2 小时前
MySQL教程之:批量使用mysql
数据库·mysql
Minxinbb2 小时前
MySQL主从:如何处理“Got Fatal Error 1236”或 MY-013114 错误(percona译文)
数据库·mysql·dba
人总该做点什么3 小时前
【数据库】三、SQL语言
数据库·sql
HelloZheQ3 小时前
探索 Oracle 数据库:核心概念与实践指南
数据库·oracle
fengyehongWorld3 小时前
Oracle 表分区简介
数据库·oracle