Oracle Dataguard(主库为双节点集群)配置详解(4):配置备库
Oracle Dataguard(主库为双节点集群)配置详解(4):配置备库
目录
- Oracle Dataguard(主库为双节点集群)配置详解(4):配置备库
- 一、为备库配置静态监听
- 1、配置 listener.ora 文件
- 2、重启监听、查看监听状态
- 3、配置 tnsnames
- 4、测试连接
- 二、创建备库的 pfile 文件
- 1、在主库创建 pfile 文件并复制至备库
- 2、修改备库的初始化参数文件
- 三、创建参数文件中涉及到的目录并启动数据库到nomount
- 1、创建目录
- 2、启动备库到 nomount
一、为备库配置静态监听
1、配置 listener.ora 文件
[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、重启监听、查看监听状态
[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
文件配置内容与主库相同。
[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、测试连接
[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> create pfile='/home/oracle/inithisdg.ora' from spfile;
File created.
(2)把初始化参数文件复制到备库的$ORACLE_HOME/dbs
目录
[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、修改备库的初始化参数文件
在主库的参数文件基础上进行修改,内容如下:
[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、创建目录
# 要创建的目录如下:
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
-- 使用修改后的 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.