最近准备给一个生产项目上oracle 11g DataGuard,主备均为oracle 11.2.0.4软件,并在备库安装软件。这篇不讲述 DataGuard 的原理,只是oracle 11g DataGuard 搭建的详细过程。这次是生产库的RAC需要做一个DG,由于不知道SYS 用户密码,需要取回密码太麻烦,故不能使用 duplicate 方式,使用rman 全备 -->还原控制文件--> mount数据库还原数据文件 --> 追加日志 --> 主备同步。搭建过程中只需要修改部分参数以及网络监听,故不需要停机可白天完成,下面开始进入主题。
1、生产环境信息
系统名称 |
系统平台 |
IP地址 |
数据库版本 |
数据量 |
XXXX系统 |
Linux |
192.168.3.101 |
11.2.0.4.0 |
180G |
XXXX系统 |
Linux |
192.168.3.102 |
11.2.0.4.0 |
主库: Linux 环境下 Oracle 11.2.0.4 RAC,使用ASM 文件系统。
备库: Linux 环境下Oracle 11.2.0.4 单机文件系统管理。
2、环境安装配置
2.1 环境需求
备库操作系统平台和版本要求与主库(生产库)一致。
备库数据库软件版本要求与主库(生产库)一致。
2.2 环境检查
确认主备数据库版本(关注企业版、标准版区别,标准版支持DG功能,不支持ADG)
su – oracle
sqlplus / as sysdba
SQL> select name from v$version;
确认数据数据文件存放位置(ASM或者文件系统)
su – oracle
sqlplus / as sysdba
SQL>select name from v$datafile;
确认数据库开启归档模式(若未开启归档,需与应用沟通开归档变更实施)
su – oracle
sqlplus / as sysdba
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +ARCH
Oldest online log sequence 21
Next log sequence to archive 23
Currentlog sequence 23
确认网络连通性
主备分别执行:
telnet IP port
若无法使用 telnet工具,配置 tns 使用 tnsping 进行测试.
在主库tnsnames.ora中添加:
beijingstb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.101)(PORT =1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijingstb)
)
)
beijing =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.105)(PORT =1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijing)
)
)
在备库tnsnames.ora中添加:
beijingstb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.101)(PORT =1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijingstb)
)
)
beijing =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.105)(PORT =1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijing)
)
)
主库:
su – oracle
tnsping beijingstb
备库:
su – oracle
tnsping beijing
2.3 备库安装 Oracle 数据库软件
2.3.1 AIX环境参数配置
2.3.1.1 确认系统包
lslpp -l bos.adt.base
lslpp -l bos.adt.lib
lslpp -l bos.adt.libm
lslpp -l bos.perf.libperfstat
lslpp -l bos.perf.perfstat
lslpp -l bos.perf.proctools
lslpp -l rsct.basic.rte
lslpp -l rsct.compat.clients.rtelslpp -l libaio
2.3.1.2 编辑 hosts 文件
vi /etc/hosts
2.3.1.3 创建用户组和用户
--用户组创建
# mkgroup -'A' id='1000' adms='root' oinstall
# mkgroup -'A' id='1010' adms='root' asmadmin
# mkgroup -'A' id='1011' adms='root' asmdba
# mkgroup -'A' id='1012' adms='root' asmoper
# mkgroup -'A' id='1001' adms='root' dba
# mkgroup -'A' id='1002' adms='root' oper
--用户创建
mkuser id='1010' pgrp='oinstall' groups='dba,asmadmin,asmdba,asmoper,oper' home='/home/grid' grid
mkuser id='1000' pgrp='oinstall' groups='dba,asmdba,oper' home='/home/oracle' oracle
chuser capabilities=CAP_NUMA_ATTACH,CAP_BYPASS_RAC_VMM,CAP_PROPAGATE grid
chuser capabilities=CAP_NUMA_ATTACH,CAP_BYPASS_RAC_VMM,CAP_PROPAGATE oracle
2.3.1.4 编辑环境变量
export PS1="[`whoami`@`hostname`:"'$PWD]$'
export ORACLE_BASE=/app
export ORACLE_HOME=/app/oracle/product/11.2.0/db_1
export ORACLE_SID=jiekexu
export ORACLE_TERM=xterm
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LIBPATH=$ORACLE_HOME/lib:/usr/lib:$ORACLE_HOME/lib32
export PATH=$ORACLE_HOME/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:
export TMP=/tmp
export TEMP=/tmp
umask 022
2.3.1.5 修改内核文件
vi /etc/security/limits
修改:
default:
fsize = -1
core = 2097151
cpu = -1
data = -1
rss = -1
stack = -1
nofiles = -1
2.3.1.6 修改内存参数
vmo -p -o minperm%=3
vmo -p -o maxperm%=90
vmo -p -o maxclient%=90
vmo -p -o lru_file_repage=0
vmo -p -o strict_maxclient=1
vmo -p -o strict_maxperm=0
chdev -l sys0 -a ncargs=256
chdev -l sys0 -a maxuproc=16384
2.3.1.7 修改网络参数
no -r -o ipqmaxlen=512
no -p -o rfc1323=1
no -p -o sb_max=4194304
no -p -o tcp_recvspace=65536
no -p -o tcp_sendspace=65536
no -p -o udp_recvspace=655360
no -p -o udp_sendspace=65536
2.3.2 HPUX 环境参数配置
2.3.2.1 编辑 hosts 文件
vi /etc/hosts
2.3.2.2 创建用户组和用户
mkgroup id=300 oinstall
mkgroup id=301 dba
mkuser id=300 pgrp=oinstall groups=dba home=/home/oracle oracle
/usr/bin/chuser capabilities=CAP_NUMA_ATTACH,CAP_BYPASS_RAC_VMM,CAP_PROPAGATE oracle
2.3.2.3 编辑环境变量
export PS1="[`whoami`@`hostname`:"'$PWD]$'
export ORACLE_BASE=/app
export ORACLE_HOME=/app/oracle/product/11.2.0/db_1
export ORACLE_SID=chyjdzx7
export ORACLE_TERM=xterm
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LIBPATH=$ORACLE_HOME/lib:/usr/lib:$ORACLE_HOME/lib32
export PATH=$ORACLE_HOME/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:
export TMP=/tmp
export TEMP=/tmp
umask 022
2.3.2.4 修改端口范围
/usr/sbin/ndd -set /dev/tcp tcp_smallest_anon_port 9000
/usr/sbin/ndd -set /dev/udp udp_smallest_anon_port 9000
2.3.2.5 设置 core 文件创建信息
mkdir -p /var/cores
coreadm -g /var/cores/%f.%n.%p.%t.core -e global -e global-setid -e log -d process -d proc-setid
2.3.2.6 添加 ssh 网络连接
mkdir /usr/local
ln -s /etc/ssh /usr/local/etc
ln -s /usr/bin /usr/local/bin
2.3.2.7 修改配置参数
vi /etc/system
添加:
set noexec_user_stack=1
set semsys:seminfo_semmni=100
set semsys:seminfo_semmns=1024
set semsys:seminfo_semmsl=256
set semsys:seminfo_semvmx=32767
set shmsys:shminfo_shmmax=4294967295
set shmsys:shminfo_shmmni=100
2.3.3 Linux 环境参数配置
2.3.3.1 检查系统包
rpm -qa|grep binutils
rpm -qa|grep compat-libstdc++
rpm -qa|grep elfutils-libelf
rpm -qa|grep elfutils-libelf-devel
rpm -qa|grep expat
rpm -qa|grep gcc
rpm -qa|grep gcc-c++
rpm -qa|grep glibc
rpm -qa|grep glibc-common
rpm -qa|grep glibc-devel
rpm -qa|grep glibc-headers
rpm -qa|grep libaio
rpm -qa|grep libaio-devel
rpm -qa|grep libgcc
rpm -qa|grep libstdc++
rpm -qa|grep libstdc++-devel
rpm -qa|grep make
rpm -qa|grep sysstat
rpm -qa|grep unixODBC
rpm -qa|grep unixODBC-devel
2.3.3.2 编辑 hosts 文件(主机名和IP对应)
vi /etc/hosts
--主机名建议小写,127.0.0.1 localhost 不能忽略不写
127.0.0.1 localhost
2.3.3.3 修改配置参数
mkgroup id=300 oinstall
mkgroup id=301 dba
mkuser id=300 pgrp=oinstall groups=dba home=/home/oracle oracle
/usr/bin/chuser capabilities=CAP_NUMA_ATTACH,CAP_BYPASS_RAC_VMM,CAP_PROPAGATE oracle
2.3.3.4 修改环境变量
vi .bash_profile
export PS1="[`whoami`@`hostname`:"'$PWD]$'
export ORACLE_BASE=/app
export ORACLE_HOME=/app/oracle/product/11.2.0/db_1
export ORACLE_SID=beijingstd
export ORACLE_TERM=xterm
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export LIBPATH=$ORACLE_HOME/lib:/usr/lib:$ORACLE_HOME/lib32
export PATH=$ORACLE_HOME/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:
export TMP=/tmp
export TEMP=/tmp
umask 022
2.3.3.5 配置内核参数
vi /etc/sysctl.conf
添加:
kernel.shmmax = 4294967295
kernel.shmall = 2097152
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr=1048576
2.3.3.6 修改资源限制
vi /etc/security/limits.conf
添加:
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
2.3.3.7 修改登陆配置文件
vi /etc/pam.d/login
添加:
session required pam_limits.so
2.3.4 Oracle 软件安装
执行 ./runInstaller 出现安装界面(本节主要是参考,截图为RAC 不过搭建 MAA 时也可参考此文)
1.选择只安装软件
2.选择跳过软件更新
3.勾选两个节点
4.从左边栏选择添加 simpfied chinese
5.选择企业版
6.设置 oracle_base 和软件安装目录
7.选择用户组
8.等待自动环境检查结束
9.点击“安装”
10.用root用户执行root.sh脚本
11.安装完成,点击“关闭”
2.3.5 创建 Oracle 监听
使用 netca 命令打开图形界面,配置数据库默认监听,这里直接贴图就欧克没啥可说的了。
3、配置Oracle DataGuard
3.1 打开数据库强制日志
确认数据库日志模式
select name,log_mode,force_logging from v$database;
打开强制日志
alter database force logging;
3.2 创建备库密码文件
scp orapwbeijing [email protected]:$ORACLE_HOME/dbs/orapwbeijingstb
(有坑,一定要同步,RAC 的话,需要将节点一同步至节点2 再将节点1 密码文件传至备库,密码文件、参数文件名的大小写需要一致,不然也会出问题)
3.3 创建 standby 日志组
查看原生产库的日志信息,大小与原生产库保持一致:
set linesize 250
COLUMN groupno FORMAT a6 HEADING 'Group'
COLUMN thread FORMAT a6 HEADING 'Thread'
COLUMN member FORMAT a50 HEADING 'Member'
COLUMN redo_file_type FORMAT a10 HEADING 'Redo Type'
COLUMN group_status FORMAT a12 HEADING 'Group Status'
COLUMN member_status FORMAT a15 HEADING 'Member Status'
COLUMN bytes FORMAT 999,999 HEADING 'Size(M)'
COLUMN archived FORMAT a10 HEADING 'Archived?'
BREAK ON groupno
SELECT
to_char(f.group#) groupno
, to_char(l.thread#) thread
, f.member member
, f.type redo_file_type
, l.status group_status
, f.status member_status
, l.bytes/1024/1024 bytes
, l.archived archived
FROM
v$logfile f
, v$log l
WHERE
f.group# = l.group#
ORDER BY
f.group#, f.member;
添加 standby 日志组(日志组最好比主库多一至两组,这样可以确保在主库业务量较大的情况下不至于备库来不及应用备库日志)
alter database add standby logfile group 4 '/app/oracle/oradata/beijing/redo4.dbf' size 500m;
alter database add standby logfile group 5 '/app/oracle/oradata/beijing/redo5.dbf' size 500m;
alter database add standby logfile group 6 '/app/oracle/oradata/beijing/redo6.dbf' size 500m;
alter database add standby logfile group 7 '/app/oracle/oradata/beijing/redo7.dbf' size 500m;
alter database add standby logfile group 8 '/app/oracle/oradata/beijing/redo8.dbf' size 500m;
3.4 修改主库参数文件
3.4.1 直接修改参数文件方式
创建pfile文件:
create pfile='/home/oracle/initbeijing.ora' from spfile;
添加以下参数:
vi /home/oracle/initbeijing.ora
log_archive_config='dg_config=(beijing, beijingstb)'
log_archive_dest_1='location=/app/oracle/arch valid_for=(all_logfiles,all_roles) db_unique_name= beijing'
log_archive_dest_2='service=orclstb LGWR ASYNC
valid_for=(online_logfiles,primary_role)
db_unique_name= beijingstb'
log_archive_dest_state_1='enable'
log_archive_dest_state_2='enable'
LOG_ARCHIVE_MAX_PROCESSES=10
fal_server=' beijingstb '
db_file_name_convert='/app/oracle/oradata/beijingstb','/app/oracle/oradata/beijing'
log_file_name_convert='/app/oracle/oradata/beijingstb','/app/oracle/oradata/beijing'
standby_file_management='AUTO'
创建spfile:
create spfile from pfile='/home/oracle/initbeijing.ora';
3.4.2 使用命令在数据库启动状态下进行参数修改:
--建议使用此方法修改参数,请按自己实际环境参考修改,如修改出现问题可用备份还原,
--如用以上方法修改可导致主库下次启动时出错,实例无法启动
alter system set db_unique_name= beijing;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(beijing,beijingstb)' ;
alter system set LOG_ARCHIVE_DEST_1='LOCATION=/app/oracle/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME= beijing;
alter system set LOG_ARCHIVE_DEST_2='SERVICE=beijingstb LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME= beijingstb;
alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;
alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;
alter system set FAL_SERVER= beijingstb;
alter system set FAL_CLIENT= beijing;
alter system set standby_file_management=auto;
alter system set db_file_name_convert='/app/oracle/oradata/beijingstb','/app/oracle/oradata/beijing' scope=spfile;
alter system set log_file_name_convert='/app/oracle/oradata/beijingstb','/app/oracle/oradata/beijing' scope=spfile;
修改完后 create pfile='/home/oracle/pfile20190729.ora' from spfile;
将此 pfile 传至备库去修改,然后使用 pfile 启动到 nomount
最最后一步记得重新创新spfile,下次启动时则可以自动使用spfile启动。
create spfile from pfile;
3.5 创建备库参数文件
传输主库参数文件到备库:
scp /home/oracle/pfile20190729.ora [email protected]:/home/oracle/
修改备库参数文件:
cp /home/oracle/pfile20190729.ora /home/oracle/pfile20190729.ora_bak
vi /home/oracle/pfile20190729.ora
DB_UNIQUE_NAME=beijingstb
log_archive_config='dg_config=(beijingstb, beijing)'
log_archive_dest_1='location=/app/oracle/arch
valid_for=(all_logfiles,all_roles)
db_unique_name=beijingstb'
log_archive_dest_2='service=beijing ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=beijing'
log_archive_dest_state_1='enable'
log_archive_dest_state_2='enable'
log_archive_format='%t_%s_%r.dbf'
log_archive_max_processes=10
db_file_name_convert='/app/oracle/oradata/beijing','/app/oracle/oradata/beijingstb'
log_file_name_convert='/app/oracle/oradata/beijing','/app/oracle/oradata/beijingstb'
3.6 主备库添加网络服务名
在主库tnsnames.ora中添加:
beijingstb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijingstb)
)
)
beijing =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.105)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijing)
)
)
在备库tnsnames.ora中添加:
beijingstb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijingstb)
)
)
beijing =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.105)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = beijing)
)
)
3.7 备库添加监听静态注册
备库在listener.ora中添加:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /app/oracle/product/11.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = beijingstb)
(ORACLE_HOME = /app/oracle/product/11.2.0/db_1)
(SID_NAME = beijingstb)
)
)
------lsnrctl status
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME =beijingstd)
(ORACLE_HOME = /app/oracle/product/11.2.0/db_1)
(SID_NAME = beijingstd)
)
)
4、 数据库初始化
4.1 备份初始化恢复(两种方式)
4.1.1 远程在线初始化(不知主库sys密码)
利用rman的duplicate生成备库:
rman target sys/xxxxx@beijing auxiliary sys/xxxxxx@beijingstb
duplicate target database for standby from active database;
4.1.2 利用 rman 备份片生成备库:
--主库建立备份目录,注意 oracle 权限
mkdir -p /backup/backup/backup20190730/
sqlplus / as sysdba
--主库切换日志
alter system archive log current;
--主库利用rman备份片生成备库(由于不知道主库sys密码,数据量也较小,使用RMAN备份传输至备库)
rman target /
run {
allocate channel c1 type disk ;
allocate channel c2 type disk ;
allocate channel c3 type disk ;
allocate channel c4 type disk ;
backup as compressed backupset database format '/backup/backup20190730/%d_%I_%s_%p.bak';
backup as compressed backupset archivelog all format '/backup/backup20190730/%d_%I_%s_%p.arc';
backup current controlfile for standby format '/backup/backup20190730/%d_%I_%s_%p.ctl';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
将备份传输至备库
[oracle@up rmanbk]$ scp beijing_3078169696_*192.168.3.105:/backup/backup20190730/
使用 pfile 启动至 nomount 状态,恢复控制文件
SQL> startup nomount pfile='/home/oracle/pfile20190729.ora';
rman target /
restore standby controlfile from '/backup/backup20190730/SDZZSKP_1470960497_14179_1.ctl';
启动数据库至 mount
sql 'alter database mount';
指定 catalog 还原、恢复数据库
--rman 列出备份文件
rman target /
list backup;
--注册从源数据库拷贝过来的备份集到rman中
RMAN> catalog start with'/backup/backup20190730/';
……
Do you really want to catalog the abovefiles (enter YES or NO)? yes
cataloging files...
cataloging done
恢复数据库
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
restore database;
recover database;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
恢复过程中报错可忽略
--这里会报错,没有恢复归档日志所致,可忽略
released channel: c1
released channel: c2
released channel: c3
released channel: c4
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 7/30/2019 20:55:02
RMAN-06054: media recovery requesting unknown archived log for thread 2 with sequence 1595 and starting SCN of 14566378244303
4.2 启动备库日志应用
alter database recover managed standby database disconnect from session;
或者使用实时的日志应用
alter database recover managed standby database using current logfile disconnect from session;
查看备库同步情况
set linesize 150;
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed fromv$dataguard_stats where name in ('transport lag','apply lag');
NAME VALUE UNIT TIME_COMPUTED
------------- -------------------------------------------------- ------------------------------
transport lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:58:04
apply lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:58:04
4.3 取消应用日志然后启动备库为read only(11g新特性)
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Alter dabatase open;
使用实时的日志应用
alter database recover managed standby database using current logfile disconnect from session;
查看备库同步情况
set linesize 150;
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed from v$dataguard_stats where name in ('transport lag','apply lag');
NAME VALUE UNIT TIME_COMPUTED
------------- -------------------- ------------------------------ ------------------------------
transport lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:59:04
apply lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:59:04
4.4 验证 DataGuard 状态
查询数据库角色:
select name,database_role from v$database;
查询备库日志应用进程:
在备库(Standby)查询,检查日志应用进程是否开启 MRP0 进程
select pid,process,status from v$managed_standby;
SQL> select pid,process,status from v$managed_standby;
PID PROCESS STATUS
---------- --------- ------------
21589 ARCH CONNECTED
21591 ARCH CONNECTED
21593 ARCH CONNECTED
21595 RFS IDLE
21597 RFS IDLE
21604 RFS IDLE
9809 MRP0 WAIT_FOR_LOG
--MRP0 即为归档应用进程。
查看日志应用状态,确保每一个日志都可以被应用:
SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# APPLIED
---------- ---------
1410 YES
1411 YES
1412 YES
1413 YES
1414 YES
查看备库同步情况
set linesize 150;
set pagesize 20;
column name format a13;
column value format a20;
column unit format a30;
column TIME_COMPUTED format a30;
select name,value,unit,time_computed from v$dataguard_stats where name in ('transport lag','apply lag');
NAME VALUE UNIT TIME_COMPUTED
------------- -------------------- ------------------------------ ------------------------------
transport lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:59:59
apply lag +00 00:00:00 day(2) to second(0) interval 07/30/2019 20:59:59
4.5 主备库切换测试
将备库的角色切换为主库:
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY with session shutdown;
5 、备库应急切换测试
模拟情景由于主库故障无法正常 switchover,需要执行 failover,强制备库切换为主库并接管业务
5.1 停止应用恢复模式
alter database recover managed standby database finish force;
5.2 转换备库为主库
alter database commit to switchover to primary;
5.3 重启数据库进行业务测试
alter database open;
6. 重新生成 DataGuard 备库
由于切换测试已经将 DataGuard 进行了 failover 类型的切换,所以无法进行逆向操作,只能重新 进行 DataGuard 的数据初始化,重复第四章节即可。
最后,以上步骤我以整理成文档,公众号【JiekeXu之路】后台回复【ADG下载】获取百度云链接,习惯用 github 的也提供了下载链接,可自行回复关键字选择下载。
80%
推荐阅读:
模拟真实环境下超简单超详细的 MySQL 5.7 安装
(长按添加微信公众号,更多精彩内容不错过!)
码字不易,点赞、转发是一种对作者的鼓励!