Oracle Dataguard(主库为 Oracle 11g 单节点)配置详解(3):配置备用数据库
目录
- Oracle Dataguard(主库为 Oracle 11g 单节点)配置详解(3):配置备用数据库
- 一、为备库配置监听
- 二、修改备库的配置文件
- 1、把主库的初始化参数文件和密码文件复制到备库相应目录下
- 2、修改备库的初始化参数文件
- 3、使用静态初始化参数文件生成 spfile 文件
- 三、创建参数文件中涉及到的目录并启动数据库到nomount
- 1、创建目录
- 2、启动备库的数据库到 nomount
一、为备库配置监听
[oracle@oradg admin]$ cd $ORACLE_HOME/network/admin
[oracle@oradg admin]$ ll
总用量 12
-rw-r--r-- 1 oracle oinstall 370 12月 30 21:28 listener.ora
drwxr-xr-x 2 oracle oinstall 64 12月 30 21:17 samples
-rw-r--r-- 1 oracle oinstall 381 12月 17 2012 shrept.lst
-rw-r--r-- 1 oracle oinstall 223 12月 30 21:28 sqlnet.ora
修改文件listener.ora
,内容如下:
[oracle@oradg 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 = oradg)(PORT = 1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=hisdbdg)
(SID_NAME=oradg)
(ORACLE_HOME=/usr/local/oracle/product/11.2.0/db_1)
)
)
ADR_BASE_LISTENER = /usr/local/oracle
修改文件tnsnames.ora
,内容如下:
[oracle@oradg admin]$ vi tnsnames.ora
HISDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ora)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdb)
)
)
HISDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = oradg)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = hisdbdg)
)
)
查看备库的监听信息:
[oracle@oradg admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 01-JAN-2025 17:18:27
Copyright (c) 1991, 2013, Oracle. All rights reserved.
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 01-JAN-2025 17:17:37
Uptime 0 days 0 hr. 0 min. 50 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/oradg/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oradg)(PORT=1521)))
Services Summary...
Service "hisdbdg" has 1 instance(s).
Instance "oradg", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
二、修改备库的配置文件
1、把主库的初始化参数文件和密码文件复制到备库相应目录下
(1)在主库上执行如下操作
[oracle@ora admin]$ cd $ORACLE_HOME/dbs
[oracle@ora dbs]$ ll
总用量 24
-rw-rw---- 1 oracle oinstall 1544 1月 1 17:31 hc_ora.dat
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1384 1月 1 17:41 initora.ora
-rw-r----- 1 oracle oinstall 24 12月 30 21:46 lkHISDB
-rw-r----- 1 oracle oinstall 1536 12月 30 21:46 orapwora
-rw-r----- 1 oracle oinstall 3584 1月 1 17:32 spfileora.ora
-- 复制静态初始化参数文件到备库
[oracle@ora dbs]$ scp initora.ora oracle@oradg:$ORACLE_HOME/dbs/
oracle@oradg's password:
initora.ora 100% 1384 1.4KB/s 00:00
-- 复制密码文件到备库
[oracle@ora dbs]$ scp orapwora oracle@oradg:$ORACLE_HOME/dbs/
oracle@oradg's password:
orapwora
(2)查看备库的初始化参数文件信息
[oracle@oradg ~]$ cd $ORACLE_HOME/dbs/
[oracle@oradg dbs]$ ll
总用量 12
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1384 1月 1 17:51 initora.ora
-rw-r----- 1 oracle oinstall 1536 1月 1 17:52 orapwora
2、修改备库的初始化参数文件
# 备库的初始化参数文件中需要修改的内容如下:
*.db_unique_name='hisdbdg' # 修改,保持唯一
*.log_archive_config='dg_config=(hisdb,hisdbdg)' # 与主库保持一致,不需修改
*.db_file_name_convert='/usr/local/oradata/hisdb/','/usr/local/oradata/hisdbdg/'
*.log_file_name_convert='/usr/local/oradata/hisdb/','/usr/local/oradata/hisdbdg/'
# *.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hisdb' # 主库中该参数配置为主库的db_unique_name
*.log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=hisdbdg' # 备库中该参数配置为备库的db_unique_name
# *.log_archive_dest_2='service=hisdbdg lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=hisdbdg' # 主库中service参数为备库的服务名,db_unique_name参数配置为备库的db_unique_name
*.log_archive_dest_2='service=hisdb lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=hisdb' # 在备库中service参数为主库的服务名,db_unique_name参数配置为主库的db_unique_name
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.standby_file_management='auto'
*.fal_server='hisdb'
*.fal_client='hisdbdg'
修改后的初始化参数文件内容如下:
[oracle@oradg dbs]$ vi initora.ora
ora.__db_cache_size=792723456
ora.__java_pool_size=4194304
ora.__large_pool_size=8388608
ora.__oracle_base='/usr/local/oracle'#ORACLE_BASE set from environment
ora.__pga_aggregate_target=499122176
ora.__sga_target=1073741824
ora.__shared_io_pool_size=0
ora.__shared_pool_size=255852544
ora.__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_file_name_convert='/usr/local/oradata/hisdb/','/usr/local/oradata/hisdbdg/'
*.log_file_name_convert='/usr/local/oradata/hisdb/','/usr/local/oradata/hisdbdg/'
*.db_block_size=8192
*.db_domain=''
*.db_name='hisdb'
*.db_recovery_file_dest_size=4385144832
*.db_recovery_file_dest='/usr/local/oracle/fast_recovery_area'
*.db_unique_name='hisdbdg'
*.diagnostic_dest='/usr/local/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=oraXDB)'
*.fal_client='hisdb'
*.fal_server='hisdbdg'
*.log_archive_config='dg_config=(hisdb,hisdbdg)'
*.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=hisdb 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=499122176
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=1073741824
*.standby_file_management='auto'
*.undo_tablespace='UNDOTBS1'
3、使用静态初始化参数文件生成 spfile 文件
(1)修改静态初始化参数文件的名称
[oracle@oradg dbs]$ cd $ORACLE_HOME/dbs
[oracle@oradg dbs]$ ll
总用量 24
-rw-rw---- 1 oracle oinstall 1544 1月 1 18:53 hc_oradg.dat
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1559 1月 1 19:08 initora.ora
-rw-r----- 1 oracle oinstall 1536 1月 1 17:52 orapwora
-rw-r----- 1 oracle oinstall 4608 1月 1 18:52 spfileoradg.ora
[oracle@oradg dbs]$ mv initora.ora initoradg.ora
[oracle@oradg dbs]$ ll
总用量 24
-rw-rw---- 1 oracle oinstall 1544 1月 1 18:53 hc_oradg.dat
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r--r-- 1 oracle oinstall 1559 1月 1 19:08 initoradg.ora
-rw-r----- 1 oracle oinstall 1536 1月 1 17:52 orapwora
-rw-r----- 1 oracle oinstall 4608 1月 1 18:52 spfileoradg.ora
(2)生成 spfile 文件
SQL> create spfile from pfile;
File created.
三、创建参数文件中涉及到的目录并启动数据库到nomount
1、创建目录
# 要创建的目录如下:
/usr/local/oracle/fast_recovery_area
/usr/local/oradata/hisdbdg
/usr/local/oracle/admin/hisdbdg/adump
/usr/local/oradata/hisdbdg
/usr/local/oracle/fast_recovery_area/hisdbdg
[oracle@oradg ~]$ mkdir -p /usr/local/oracle/fast_recovery_area
[oracle@oradg ~]$ mkdir -p /usr/local/oradata/hisdbdg
[oracle@oradg ~]$ mkdir -p /usr/local/oracle/admin/hisdbdg/adump
[oracle@oradg ~]$ mkdir -p /usr/local/oradata/hisdbdg
[oracle@oradg ~]$ mkdir -p /usr/local/oracle/fast_recovery_area/hisdbdg
2、启动备库的数据库到 nomount
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 331350920 bytes
Database Buffers 729808896 bytes
Redo Buffers 5517312 bytes