Oracle data guard部署
本教程基于oracle19c,rpm安装包搭建,参数和数据同步还没有操作,操作的同时请频繁启动和关闭数据库,监听,保证过程没有出现问题
服务器配置
主机名 | ip |
---|---|
ORCLCDB | 10.1.11.200 |
ORCLCDBDG | 10.1.11.190 |
ORCLCDB 为主库,ORCLCDBDG 为备库
两个服务器均关闭防火墙
配置vim /etc/sysconfig/selinux
SELINUXTYPE=targeted
SELINUX=disabled
主库:
1. oracle安装完成之切换到oracle用户配置环境变量
export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$PATH:/opt/oracle/product/19c/dbhome_1/bin
export NLS_LANG=“SIMPLIFIED CHINESE_CHINA.AL32UTF8” --语言配置可能会报错
export ORACLE_SID=ORCLCDB
2. 配置参数
sqlplus / as sysdba
--配置DG主备库
alter system set log_archive_config='DG_CONFIG=(ORCLCDB,ORCLCDBDG)' scope=both;
--配置本地归档路径
alter system set log_archive_dest_1='LOCATION=/opt/oracle/oradata/orcl VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCLCDB' scope=both;
--配置备库归档
alter system set log_archive_dest_2='SSERVICE=ORCLCDBDG LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLCDBDG' scope=both;
alter system set log_archive_dest_state_1=ENABLED scope=both;
alter system set log_archive_dest_state_2=ENABLED scope=both;
alter system set FAL_SERVER=ORCLCDBDG scope=both;
alter system set FAL_CLIENT=ORCLCDB scope=both;
alter system set standby_file_management=auto;
注:文章中主备库文件转换,如果两个库位置相同可以不配置
create pfile from spfile;生成参数文件
参数文件所在位置以及例子
vim /opt/oracle/product/19c/dbhome_1/dbs/initORACLE.ora
ORACLE.__unified_pga_pool_size=0
*.audit_file_dest='/opt/oracle/admin/ORCLCDB/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl','/opt/oracle/oradata/ORCLCDB/control02.ctl'
*.db_block_size=8192
*.db_name='ORCLCDB'
*.diagnostic_dest='/opt/oracle'
*.enable_pluggable_database=true
*.fal_client='ORCLCDB'
*.fal_server='ORCLCDBDG'
*.local_listener='LISTENER_ORCLCDB'
*.log_archive_config='DG_CONFIG=(ORCLCDB,ORCLCDBDG)'
*.log_archive_dest_1='LOCATION=/opt/oracle/oradata/orcl VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCLCDB'
*.log_archive_dest_2='SERVICE=ORCLCDBDG LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLCDBDG'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.pga_aggregate_target=1589m
*.processes=320
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4764m
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
3. 设置文件密码并将密码和参数拷贝到备库
在dba文件中操作
orapwd file = orapwORCLCDB password = orapw#ORCLCDB1 entries=5
scp $ORACLE_HOME/dbs/orapwORCLCDB oracle@10.1.11.190:$ORACLE_HOME/dbs/
scp $ORACLE_HOME/dbs/initORCLCDBoracle@10.1.11.190:$ORACLE_HOME/dbs/
4.配置监听和服务名解析
vim /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora
SID_LIST_LISTENER=
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCLCDB)
(ORACLE_HOME = /opt/oracle/product/19c/dbhome_1)
(SID_NAME = ORCLCDB)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.200)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
5.配置
vim /opt/oracle/product/19c/dbhome_1/network/admin/tnsnames.ora
ORCLCDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.200)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCLCDB)
)
)
LISTENER_ORCLCDB =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.200)(PORT = 1521))
ORCLCDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.190)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCLCDBDG)
)
)
备库:
切换oracle用户
1. 首先将主库dbs文件修改为备库名称
mv initORCLCDBDG.ora initORCLCDBDG.ora
mv orapwORCLCDB orapwORCLCDBDG
2. 修改initORCLCDBDG 文件
*.audit_file_dest='/u01/app/oracle/admin/ORCLCDBDG/adump'
*.control_files='/oradata/BANGKOKDG/controlfile/o1_mf_kvodmbdo_.ctl','/oradata/fast_recovery_area/BANGKOKDG/controlfile/o1_mf_kvodmbfp_.ctl'
*.db_file_name_convert='/oradata/BANGKOK/datafile','/oradata/BANGKOKDG/datafile'
*.db_name='ORCLCDB'
*.db_recovery_file_dest='/oradata/fast_recovery_area'
*.db_unique_name='ORCLCDBDG'
*.fal_client='ORCLCDBDG'
*.fal_server='ORCLCDB'
*.log_archive_config='DG_CONFIG=(ORCLCDBDG,ORCLCDB)'
*.log_archive_dest_1='LOCATION=/oradata/archVALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCLCDBDG'
*.log_archive_dest_2='SERVICE=ORCLCDB LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLCDBDG
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
备库文件例子
*.audit_file_dest='/opt/oracle/admin/ORCLCDB/adump'
*.audit_trail='db'
*.compatible='19.0.0'
*.control_files='/opt/oracle/oradata/ORCLCDB/control01.ctl','/opt/oracle/oradata/ORCLCDB/control02.ctl'
*.db_block_size=8192
*.db_name='ORCLCDB'
*.db_unique_name='ORCLCDBDG'
*.diagnostic_dest='/opt/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLCDBXDB)'
*.enable_pluggable_database=true
*.fal_client='ORCLCDBDG'
*.fal_server='ORCLCDB'
*.local_listener='LISTENER_ORCLCDB'
*.log_archive_config='DG_CONFIG=(ORCLCDBDG,ORCLCDB)'
*.log_archive_dest_1='LOCATION=/opt/oracle/oradata/orcl VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCLCDBDG'
*.log_archive_dest_2='SERVICE=ORCLCDBDG LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLCDB'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.nls_language='SIMPLIFIED CHINESE'
*.nls_territory='CHINA'
*.open_cursors=300
*.pga_aggregate_target=1589m
*.processes=320
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4764m
*.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
3. 修改$ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = ORCLCDBDG)
(ORACLE_HOME = /opt/oracle/product/19c/dbhome_1)
(SID_NAME = ORCLCDBDG)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.190)(PORT = 1521))
)
)
4. 修改tnsnames.ora
ORCLCDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.200)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCLCDB)
)
)
ORCLCDBDG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.11.190)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCLCDBDG)
)
)
LISTENER_ORCLCDBDG =
(ADDRESS = (PROTOCOL = TCP)(HOST = 12.1.11.190)(PORT = 1521))
配置主备库完成之后
两个库同事启动监听,启动数据库,查看监听和数据库的状态
RMAN连接主库和备库
rman target sys/orapw#ORCLCDB1@ORCLCDB auxiliary sys/orapw#ORCLCDB1@ORCLCDBDG
没有报错说明住备库连接成功
数据同步请参考文章