文章目录
- 一、环境配置
- 1、主机环境
- 2、host文件配置
- 二、主库配置
- 1、 开启归档
- 2、redo日志
- 3、修改参数文件
- 4、配置TNS文件
- 5、静态监听
- 6、拷贝密码文件
- 三、备库配置
- 1、开启归档
- 2、redo日志
- 3、修改参数文件
- 4、配置TNS文件
- 5、配置静态监听
- 四、构建DG
- 1、验证监听
- 2、主库登入rman,复制数据库至备库
- 3、开启实时同步
一、环境配置
1、主机环境
类型 | 主机名 | IP |
---|---|---|
主库 | p19c | 192.168.229.150 |
备库 | p19cstd | 192.168.229.151 |
这里选择做两个19c单机环境
tip:数据库服务名与主机名一致
- 19c的安装可以参考以下教程,教程是以p19c为例,在安装p19cstd时,需要将所有的p19c替换成p19cstd
Oracle 19c静默安装教程
2、host文件配置
配置hostname:
# 主库
hostnamectl set-hostname p19c
# 备库
hostnamectl set-hostname p19cstd
配置hosts文件:
cat <<EOF>>/etc/hosts
#Public IP
192.168.229.150 p19c
192.168.229.151 p19cstd
EOF
二、主库配置
1、 开启归档
- 查看oracle归档状态
archive log list
- 关闭数据库,并启动到mount状态
shutdown immediate;
startup mount;
- 修改归档位置
mkdir -p /u01/app/archive
chown -R oracle:oinstall /u01/app/
# 在sql中执行,修改归档位置
alter system set log_archive_dest_1='location=/u01/app/archive';
- 启用归档模式和强制归档
alter database archivelog;
alter database force logging;
alter database open;
- 查看修改后的归档状态
archive log list;
- 切换在线日志,验证归档是否正常
alter system switch logfile;
!ls /u01/app/archive
2、redo日志
- 查询现有redo日志的数量
select group#,type,member from v$logfile;
- 查询现有redo日志的容量
select group#,bytes/1024/1024 as MB,status from v$log;
- 创建standby日志组,容量要和redo相同,数量是redo当前数量+1
mkdir -p /u01/app/oradata/P19C
chown -R oracle:oinstall /u01/app/
alter database add standby logfile
group 6 ('/u01/app/oradata/P19C/standby_redo04.log') size 200m reuse,
group 7 ('/u01/app/oradata/P19C/standby_redo05.log') size 200m reuse,
group 8 ('/u01/app/oradata/P19C/standby_redo06.log') size 200m reuse,
group 9 ('/u01/app/oradata/P19C/standby_redo07.log') size 200m reuse;
- 确认状态
select group#,status,used from v$standby_log;
3、修改参数文件
# DG_CONFIG(主库名,备库名)
alter system set log_archive_config='DG_CONFIG=(p19c,p19cstd)';
# LOCATION是主库的归档日志,DB_UNIQUE_NAME是主库名
alter system set log_archive_dest_1='LOCATION=/u01/app/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=p19c';
# SERVICE=备库名,DB_UNIQUE_NAME=备库名
alter system set log_archive_dest_2='SERVICE=p19cstd VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=p19cstd';
alter system set log_archive_dest_state_1='enable';
alter system set log_archive_dest_state_2='enable';
# db_file_name_convert=新建的redo日志位置,主库和备库的,备库后边按照这个创建
alter system set db_file_name_convert='/u01/app/oradata/P19CSTD','/u01/app/oradata/P19C' scope=spfile;
# db_file_name_convert=新建的redo日志位置,主库和备库的,备库后边按照这个创建
alter system set log_file_name_convert='/u01/app/oradata/P19CSTD','/u01/app/oradata/P19C' scope=spfile;
# 备库名
alter system set fal_server='p19cstd';
# 主库名
alter system set fal_client='p19c';
alter system set standby_file_management='AUTO';
# 主库名
alter system set DB_UNIQUE_NAME='p19c' scope=spfile;
上面修改的参数有的需要重启数据库才能生效
shutdown immediate;
startup;
4、配置TNS文件
cd $ORACLE_HOME/network/admin/
netmgr,配置tns,监听
vim tnsnames.ora
LISTENER_P19C =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19c)(PORT = 1521))
P19C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19c)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = p19c)
)
)
P19CSTD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19cstd)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = p19cstd)
)
)
重启监听
lsnrctl stop
lsnrctl start
- 测试监听是否配资成功
tnsping p19c
tnsping p19cstd
5、静态监听
cd $ORACLE_HOME/network/admin
vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19c)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = p19c)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0)
(SID_NAME = p19c)
)
)
监听重载
lsnrctl reload
6、拷贝密码文件
# 如果下列命令找不到位置,就执行 cd $ORACLE_HOME/dbs
cd /u01/app/oracle/product/19.3.0/dbs
# 密码文件名字为orapw+实例名
scp orapwp19c oracle@p19cstd:/u01/app/oracle/product/19.3.0/dbs/
备库有两个密码文件,其中一个是主库的密码文件
三、备库配置
1、开启归档
- 查看oracle归档状态
archive log list
- 关闭数据库,并启动到mount状态
shutdown immediate;
startup mount;
- 修改归档位置
mkdir -p /u01/app/archive
chown -R oracle:oinstall /u01/app/
# 在sql中执行,修改归档位置
alter system set log_archive_dest_1='location=/u01/app/archive';
- 启用归档模式和强制归档
alter database archivelog;
alter database force logging;
alter database open;
- 查看修改后的归档状态
archive log list;
- 切换在线日志,验证归档是否正常
alter system switch logfile;
!ls /u01/app/archive
2、redo日志
- 查询现有redo日志的数量
select group#,type,member from v$logfile;
- 查询现有redo日志的容量
select group#,bytes/1024/1024 as MB,status from v$log;
- 创建standby日志组,容量要和redo相同,数量是redo当前数量+1
mkdir -p /u01/app/oradata/P19CSTD
chown -R oracle:oinstall /u01/app/
alter database add standby logfile
group 6 ('/u01/app/oradata/P19CSTD/standby_redo04.log') size 200m reuse,
group 7 ('/u01/app/oradata/P19CSTD/standby_redo05.log') size 200m reuse,
group 8 ('/u01/app/oradata/P19CSTD/standby_redo06.log') size 200m reuse,
group 9 ('/u01/app/oradata/P19CSTD/standby_redo07.log') size 200m reuse;
- 确认状态
select group#,status,used from v$standby_log;
3、修改参数文件
备库要创建/u01/app/oracle/admin/oraclestd/adump文件,要不然无法启动
mkdir -p /u01/app/oracle/admin/p19cstd/adump
# DG_CONFIG(备库名,主库名)
alter system set log_archive_config='DG_CONFIG=(p19cstd,p19c)';
# LOCATION是备库的归档日志,DB_UNIQUE_NAME是备库名
alter system set log_archive_dest_1='LOCATION=/u01/app/archive VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=p19cstd';
# SERVICE=主库名,DB_UNIQUE_NAME=主库名
alter system set log_archive_dest_2='SERVICE=p19c VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=p19c';
alter system set log_archive_dest_state_1='enable';
alter system set log_archive_dest_state_2='enable';
# db_file_name_convert=新建的redo日志位置,主库和备库的,备库后边按照这个创建
alter system set db_file_name_convert='/u01/app/oradata/P19C','/u01/app/oradata/P19CSTD' scope=spfile;
# db_file_name_convert=新建的redo日志位置,主库和备库的,备库后边按照这个创建
alter system set log_file_name_convert='/u01/app/oradata/P19C','/u01/app/oradata/P19CSTD' scope=spfile;
# 主库名
alter system set fal_server='p19c';
# 备库名
alter system set fal_client='p19cstd';
alter system set standby_file_management='AUTO';
# 备库名
alter system set DB_UNIQUE_NAME='p19cstd' scope=spfile;
上面修改的参数有的需要重启数据库才能生效
shutdown immediate;
startup;
4、配置TNS文件
cd $ORACLE_HOME/network/admin/
netmgr,配置tns,监听
vim tnsnames.ora
LISTENER_P19CSTD =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19cstd)(PORT = 1521))
P19CSTD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19cstd)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = p19cstd)
)
)
P19C =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19c)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = p19c)
)
)
重启监听
lsnrctl stop
lsnrctl start
- 测试监听是否配资成功
tnsping p19c
tnsping p19cstd
5、配置静态监听
cd $ORACLE_HOME/network/admin
vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = p19cstd)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = p19cstd)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0)
(SID_NAME = p19cstd)
)
)
监听重载
lsnrctl reload
再次测试监听
四、构建DG
1、验证监听
主库:
sqlplus sys/123@p19c as sysdba
sqlplus sys/123@p19cstd as sysdba
备库:
sqlplus sys/123@p19c as sysdba
sqlplus sys/123@p19cstd as sysdba
2、主库登入rman,复制数据库至备库
- 先将备库置为nomount状态
sqlplus sys/123@p19cstd as sysdba
shutdown immediate;
startup nomount;
# 修改参数standby_file_management
alter system set standby_file_management=MANUAL;
rman target sys/123@p19c auxiliary sys/123@p19cstd
构建备库
duplicate target database for standby from active database nofilenamecheck using compressed backupset;
3、开启实时同步
- 备库
# 查询备库状态是否已经mount:
select open_mode from v$database;
# 打开数据库
alter database open;
alter database recover managed standby database using current logfile disconnect from session;
关闭同步:即停止 mgr 进程(这里不用关闭,了解就行)
alter database recover managed standby database cancel;
查看数据库打开状态:
READ ONLY WITH APPLY代表ADG启动成功
select open_mode from v$database;