环境说明:
RAC
hosts 文件配置:
#public-ip 192.169.100.130 green1 192.169.100.131 green2 192.169.100.204 rac-dg #VIP 192.169.100.132 rac1-vip 192.169.100.133 rac2-vip #scan-ip 192.169.100.134 rac-scan #priv-ip 10.0.0.1 rac1-priv1 10.0.0.2 rac2-priv2
Standby (备库只需要安装数据库软件即可,不需创建数据库)
说明:
1. instance_name 和 db_name 和原库保持一致,因为备库没有创建数据库,所以没有实例名和DB_name,所以这里的实例名和数据库名是只参数文件中需要写入的名字
2. service_names 和 db_unique_name,这两个名字主要用在监听配置和主库同步日志到备库是用到的名字,db_unique_name 必须不一致。
主要关注: 1.实例名称: 写在spile和pfile中,用来控制系统参数 2.DB name: 数据库名称,这个名称主备库必须保持一致(在参数文件中的db_name) 3.DB_UNIQUE_NAME 用为唯一区分不同的服务器名称,主备需要设置为不同的值 4.service name 写在tnsnames.ora 中用来做主备的联通(通过tnsping测试)。
查看以上名称可以使用如下语句:
查看所有名称:
show parameter service_name;
1、查询数据库名:select name,dbid from v$database;或者show parameter db_name; 2、查询实例名:select instance_name from v$instance;或者show parameter instance_name; 3、查询数据库域名:select value from v$parameter where name='db_domain';或者show parameter domain; 4、查询数据库服务器:select value from v$parameter where name='service_name';或者show parameter service;或者show parameter names; 5、数据库服务名:此参数是数据库标识类参数,用service_name表示。数据库如果有域,则数据库服务名就是全局数据库名;
如果没有,则数据库服务名就是数据库名。查询:show parameter service_name;
3. 主库使用ASM管理磁盘,而备库使用文件系统管理磁盘。所以需要修改文件映射。
配置过程:
主库前期准备:
(1)设置强制写日志 [oracle@Oracle11g2 admin]$ sqlplus / as sysdba SQL> select FORCE_LOGGING from v$database; NO SQL> alter database force logging; SQL> select FORCE_LOGGING from v$database; YES (2)修改数据库运行在归档模式下 archive log list sql>SHUTDOWN IMMEDIATE; sql>STARTUP MOUNT; sql>ALTER DATABASE ARCHIVELOG; sql> ALTER DATABASE OPEN; 修改归档的路径: alter system set log_archive_dest_1='location=/u01/app/arch/dg';
查看归档路径和空间大小:
archive log list;
col total_size for a10;
col free_size for a20;
select name,total_mb/1024 || 'G' as total_size , free_mb/1024 || 'G' as free_size from v$asm_diskgroup;
1.配置主机名和IP地址的对应:(主备库都需要添加ip地址和主机名称的对应,是为了在监听中的host 作为连接,RAC环境需要添加public ip和vip的映射)
vi /etc/hosts
#public-ip
192.169.100.130 green1
192.169.100.131 green2
192.169.100.204 rac-dg
#VIP
192.169.100.132 rac1-vip
192.169.100.133 rac2-vip
#scan-ip
10.25.71.33 rac-scan
2.在主库上创建pfile:
事先备份spfile 如果使用ASM磁盘管理存储需要指定路径 不然会放于 asm磁盘组
create pfile='/tmp/initdg.ora' from spfile;
scp /tmp/initdg.ora oracle@rac-dg:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
3.复制主库的密码文件到备库,并修改名字
cp /u01/app/oracle/product/11.2.0/dbs/orapwrac1 /tmp/orapwdg
创建口令文件(密码为sys用户的密码)
orapwd file='/u01/app/oracle/product/11.2.0/dbs/orapwprimary' password=sys entries=10
scp /tmp/orapwdg oracle@rac-dg:/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
4.在主库上创建备份库需要的控制文件 (不需要启动到mount,后续如果控制文件记录的scn号和归档文件不一致,可手动处理,或则恢复到主库,让备库自动同步即可)
ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/tmp/standby.ctl';
scp standby.ctl oracle@oracle@rac-dg:/u01/app/oracle/data/orcl/controlfile
cp standby.ctl current01
cp standby.ctl current02
5.#备库工建立以下目录,保持与主库目录一致。
注意:如果tempfile没有指定在软件安装目录,那么需要在 db_file_name_convert 中指定好转换的目录的路径。
创建存放数据和日志的目录: mkdir -p /u01/app/oracle/data/orcl/datafile --数据文件 mkdir -p /u01/app/oracle/data/orcl/tempfile --临时文件 mkdir -p /u01/app/oracle/data/orcl/onlinelog --redo日志 mkdir -p /u01/app/oracle/data/orcl/controlfile --控制文件 mkdir -p /u01/app/oracle/data/orcl/archive --归档文件 创建如下目录和远端保持一致 mkdir -p /u01/app/oracle/admin/rac/adump mkdir -p /u01/app/oracle/admin/rac/dpdump mkdir -p /u01/app/oracle/admin/rac/hdump mkdir -p /u01/app/oracle/admin/rac/pfile
6.TNS和监听配置:
TNS主备库设置一致:(在ORACLE_HOME/network/admin/tnsnames.ora文件中新增如下信息)
DG = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = stdip)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = DG) ) )
RAC = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = RACIP)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = RAC) ) )
配置之后使用tnsping在主备库上分别测试是否连通:
tnsping rac
tnsping dg
出现如下信息则表示配置成功:
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 02-NOV-2020 16:34:32
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dg)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg)))
OK (30 msec)
TNS配置失败的可能有:
(1).防火墙配置未开放ip和端口
(2).主备库有ip限制
IP限制配置:
使用grid用户管理监听和网络的环境下在grid home目录下配置
/oracle/app/11.2.0/grid/network/admin/sqlnet.ora
[oracle@yymhdb2 admin]$ cat sqlnet.ora
# sqlnet.ora.yymhdb2 Network Configuration File: /oracle/app/11.2.0/grid/network/admin/sqlnet.ora.yymhdb2
# Generated by Oracle configuration tools.
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
ADR_BASE = /oracle/app/grid
tcp.validnode_checking=yes
tcp.invited_nodes=(IP1,IP2)
非grid管理的环境下在oracle heme环境下配置:
对于rac的环境,建议ip使用scan-ip或者使用vip:
使用scan ip:
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = RAC)
)
使用vip:
RAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
监听配置:
(1)主库listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = pri)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/)
(SID_NAME = dg)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
注意这里的pri和dg(pri是指一个数据库对外提供的服务,dg是指实例的名称,这里提供了一个名为pri的服务该服务下有dg这个实例)
连接时就可以使用sqlplus sys/abc123@pri as sysdba 表示连接到了dg这个实例上。
(2)备库listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = std)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/)
(SID_NAME = dg)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
配置完成之后重启监听。
并使用下面的语句验证:
(1)tnsnames配置完之后tnsping pri 和tnsping std应该成功
(2)lisenter.ora配置完之后使用sqlplus sys/abc123@pri as sysdba
sqlplus sys/abc123@std as sysdba
测试是否可以连接,如果没有联通,一般是因为没有将密码文件传输到备库。
7.主库的配置文件:
rac1.__db_cache_size=587202560
rac2.__db_cache_size=587202560
rac1.__java_pool_size=16777216
rac2.__java_pool_size=16777216
rac1.__large_pool_size=33554432
rac2.__large_pool_size=33554432
rac1.__pga_aggregate_target=654311424
rac2.__pga_aggregate_target=654311424
rac1.__sga_target=956301312
rac2.__sga_target=956301312
rac1.__shared_io_pool_size=0
rac2.__shared_io_pool_size=0
rac1.__shared_pool_size=301989888
rac2.__shared_pool_size=301989888
rac1.__streams_pool_size=0
rac2.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/rac/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.log_archive_dest_1='location=+ARCHIVELOG'
*.log_archive_dest_state_1='ENABLE'
*.control_files='+DATADG/rac/controlfile/current.261.1048800525','+DATADG/rac/controlfile/current.260.1048800525'
*.db_block_size=8192
*.db_create_file_dest='+DATADG'
*.db_domain=''
*.db_name='rac'
*.db_recovery_file_dest='+DATADG'
*.db_recovery_file_dest_size=4621074432
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)'
rac2.instance_number=2
rac1.instance_number=1
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=1600126976
*.open_cursors=300
*.processes=150
*.remote_listener='green-scan:1521'
*.remote_login_passwordfile='exclusive'
rac1.thread=1
rac2.thread=2
rac1.undo_tablespace='UNDOTBS2'
rac2.undo_tablespace='UNDOTBS1'
主库做如下修改:
使用如下语句查看主库参数配置或者生成spfile文件查看:
select name, value from v$parameter where name in
('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2','log_archive_dest_3','log_archive_dest_state_1','log_archive_dest_state_2','log_archive_dest_state_3'
,'remote_login_passwordfile','log_archive_format','log_archive_max_processes','fal_server','db_file_name_convert', 'log_file_name_convert',
'standby_file_management');
主库做如下修改,用来向备库传输归档日志,主库启用归档之后做如下配置
这两个参数只需在standby库设置,但也可以在primary库设置这两个参数,以方便switchover或failover时primary库转变为standby角色。
alter system set fal_server='DG';
alter system set fal_client='rac';
ALTER SYSTEM SET log_archive_config='DG_CONFIG=(RAC,DG)' scope=both;
alter system set LOG_ARCHIVE_DEST_2='SERVICE=DG LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DG';
ALTER SYSTEM SET log_archive_dest_state_2='ENABLE';
参数说明:
fal_server和fal_client,FAL即Fetch Archive Log,其值为Oracle Net service name,即tnsnames.ora中的服务名。
设置这两个参数可以用来解决Archive Gaps。
一旦产生了gap,fal_client会自动向fal_server请求传输gap的archivelog。
设置了这2个参数,就不需要在产生gap时手动向standby注册归档日志了。
所需要做的就是确认主库有这些归档日志,并且主库的控制文件中有这些日志的注册信息。
fal_client设置为数据库自身的service name,
fal_server设置为远端数据库的service name。
fal_server可以设置多个值,用逗号隔开。
primary:
*.fal_server='DG'
*.fal_client='rac'
standby:
*.fal_server='rac'
*.fal_client='DG'
FAL_CLIENT和FAL_SERVER是配置dataguard用到的两个参数,FAL指获取归档日志(Fetch Archived Log)
在一定的条件下,或者因为网络失败,或者因为资源紧张,会在primary和standby之间产生裂隙,也就是有些归档日志没有及时的传输并应用到standby库。因为MRP(managed recovery process)/LSP(logical standby process)没有与primary直接通讯的能力来获取丢失的归档日志。因此这些gaps通过FAL客户和服务器来解决,由初始化参数定义FAL_CLIENT和FAL_SERVER。
FAL_SERVER指定一个Oracle Net service name,standby数据库使用这个参数连接到FAL server,这个参数适用于standby站点。比如,FAL_SERVER = PrimaryDB,此处PrimaryDB是一个TNS name,指向primary库。
FAL_CLIENT指定一个FAL客户端的名字,以便FAL Server可以引用standby库,这也是一个TNS name,primary库必须适当配置此TNS name指向stanby库。这个参数也是在standby库端设置。比如,FAL_CLIENT = StandbyDB,StandbyDB是standby库的TNS name。
FAL_CLIENT和FAL_SERVER应该成对设置或改变。
这两个参数只需在standby库设置,但也可以在primary库设置这两个参数,以方便switchover或failover时primary库转变为standby角色
备库做如下修改:
修改后: *.__db_cache_size=587202560 *.__java_pool_size=16777216 *.__large_pool_size=33554432 *.__pga_aggregate_target=654311424 *.__sga_target=956301312 *.__shared_io_pool_size=0 *.__shared_pool_size=301989888 *.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/rac/adump' *.audit_trail='db' *.cluster_database=true *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/data/orcl/controlfile/current01','/u01/app/oracle/data/orcl/controlfile/current02' *.db_block_size=8192 #*.db_create_file_dest='+DATADG' *.db_domain='' *.db_name='rac' *.db_recovery_file_dest='/u01/app/oracle/data/orcl/db_recovery' *.db_recovery_file_dest_size=4621074432 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=racXDB)' *.fal_client='DG' *.fal_server='RAC' *.log_archive_format='%t_%s_%r.dbf' *.java_jit_enabled=TRUE *.job_queue_processes=1000 *.log_archive_config='DG_CONFIG=(RAC,DG)' *.log_archive_dest_1='LOCATION=/u01/app/oracle/data/orcl/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DG' *.log_archive_dest_state_1='ENABLE' *.log_archive_max_processes=4 *.log_archive_trace=0 *.memory_target=1600126976 *.open_cursors=300 *.processes=150 *.remote_listener='green-scan:1521' *.remote_login_passwordfile='exclusive' DG.thread=1 DG.undo_tablespace='UNDOTBS1' *.result_cache_max_size=536870912 *.result_cache_mode='AUTO' *.session_cached_cursors=300 *.sessions=300 *.sga_max_size=3G *.sga_target=3G *.standby_file_management='AUTO' DG.thread=1 *.undo_retention=7200 *.db_file_name_convert='+DATADG/RAC/DATAFILE','/u01/app/oracle/data/orcl//datafile'
重点关注标红参数部分
alter system set fal_server='RAC';
alter system set fal_client='DG';
ALTER SYSTEM SET log_archive_config='DG_CONFIG=(RAC,DG)' scope=both;
alter system set LOG_ARCHIVE_DEST_2='SERVICE=RAC LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=RAC';
ALTER SYSTEM SET log_archive_dest_state_2='ENABLE';
8.多个备库可以作如下配置:
主库:
*.fal_client='YYMH'
*.fal_server='YYMHSTD,yymh_std'
*.log_archive_config='DG_CONFIG=(yymh,yymhstd,yymh_std)'
*.log_archive_dest_1='location=+ARCHIVELOG'
*.log_archive_dest_2='SERVICE=yymhstd LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yymhstd'
*.log_archive_dest_3='SERVICE=yymh_std LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yymh_std'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_dest_state_3='ENABLE'
备库1:
*.fal_client='yymh_std'
*.fal_server='yymh,yymh_std'
yymh_std.instance_number=1
*.java_jit_enabled=TRUE
*.job_queue_processes=1000
*.log_archive_config='DG_CONFIG=(yymh,yymhstd,yymh_std)'
*.log_archive_dest_1='LOCATION=/data/yymh/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=yymh_std'
*.log_archive_dest_3='SERVICE=yymh LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yymh'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_3='ENABLE'
*.db_file_name_convert='+DATADG/yymh/datafile','/data/yymh/datafile'
*.log_file_name_convert='+DATADG/yymh/onlinelog','/data/yymh/onlinelog','+DATADG/yymh/tempfile','/data/yymh/tempfile/'
ALTER SYSTEM SET db_file_name_convert=('+DATADG/yymh/datafile','/data/yymh/datafile','+DATADG/yymh/tempfile','/data/yymh/tempfile/')
备库2:
*.fal_client='yymhstd'
*.fal_server='yymh,yymhstd'
yymhstd.instance_number=1
*.java_jit_enabled=TRUE
*.job_queue_processes=1000
*.log_archive_config='DG_CONFIG=(yymh,yymhstd,yymh_std)'
*.log_archive_dest_1='LOCATION=/data/yymh/arch VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=yymhstd'
*.log_archive_dest_3='SERVICE=yymh LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=yymh'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_3='ENABLE'
*.db_file_name_convert='+DATADG/yymh/datafile','/data/yymh/datafile','+DATADG/yymh/tempfile','/data/yymh/tempfile/'
*.log_file_name_convert='+DATADG/yymh/onlinelog','/data/yymh/onlinelog'
ALTER SYSTEM SET db_file_name_convert=('+DATADG/yymh/datafile','/data/yymh/datafile','+DATADG/yymh/tempfile','/data/yymh/tempfile/')
1.参数的作用:
db_file_name_convert 主数据库和备用数据库的数据文件转换目录对映(如果两数据库的目录结构不一样),
如果有多个对映,逐一指明对映关系。
2.该参数应该配置在主还是备?
备库,这个参数不能动态配置,需要重启实例,如果在主库配置需要重启主库,对于不能停的数据库是不允许的。
3.该参数的写法:
db_file_name_convert='+RACDATA/racdb/datafile/','/oradata/standby/'
9.创建添加standby redolog
在主库、从库上都配置standby redo log
在主库查看日志组的数量和每个日志文件的大小??
SQL>select * from v$log;
在备库库查看日志组的数量和每个日志文件的大小??
SQL>select * from v$log;
select group#,thread#,sequence#,archived,status from v$standby_log;
select * from v$standby_log;
standby logde 创建:
alter database add standby logfile thread 1 group 7 ('+DATA1/dg/onlinelog/standby7.log') size 50m,
group 8('+DATA1/dg/onlinelog/standby8.log') size 50m,
group 9('+DATA1/dg/onlinelog/standby9.log') size 50m,
group 10('+DATA1/dg/onlinelog/standby10.log') size 50m,
group 11('+DATA1/dg/onlinelog/standby11.log') size 50m,
group 12('+DATA1/dg/onlinelog/standby12.log') size 50m;
alter database add standby logfile thread 2 group 13 ('+DATA2/dg/onlinelog/standby13.log') size 50m,
group 14('+DATA2/dg/onlinelog/standby14.log') size 50m,
group 15('+DATA2/dg/onlinelog/standby15.log') size 50m,
group 16('+DATA2/dg/onlinelog/standby16.log') size 50m,
group 17('+DATA2/dg/onlinelog/standby17.log') size 50m,
group 18('+DATA2/dg/onlinelog/standby18.log') size 50m;
standby redolog的组数参考公式:(online redolog组数+1)*数据库线程数;
单机线程数为1,RAC一般为2。standby redolog的组成员数和大小也尽量和online redolog一样。
10.主库执行全备(包括数据文件,归档日志文件和控制文件,这里建议使用主库创建的控制文件)
run {
allocate channel c1 type disk; allocate channel c2 type disk; backup as compressed backupset filesperset 3 database format '/tmp/full_%d_%T_%s_%p'; sql 'alter system archive log current'; backup archivelog all format '/tmp/arch_%d_%T_%s_%p'; backup current controlfile format '/tmp/ctl_%d_%T_%s_%p'; }
scp * 192.168.1.2:/bak
11.启动备库
startup pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdg.ora' nomount;
create spfile from pfile;
shutdown immediate
控制文件准备好以后直接启动到mount
cp standby.ctl current01
cp standby.ctl current02
startup mount;
12.恢复数据文件
注册目录:
catalog start with '/bak/';
执行数据文件恢复
#! /bin/bash
/oracle/app/oracle/product/11.2.0/db/bin/rman target / <<EOF
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
restore database;
RELEASE CHANNEL c1;
RELEASE CHANNEL c2;
}
exit;
nohup sh restore.sh >> restore.log 2>&1 &
10.恢复归档:
#! /bin/bash /oracle/app/oracle/product/11.2.0/db/bin/rman target / <<EOF run { allocate channel c1 type disk; SET ARCHIVELOG DESTINATION TO '/data/yymh/arch'; recover database; RELEASE CHANNEL c1; } exit;
nohup sh recover.sh >> recover1.log 2>&1 &
recover database until scn 741679073877;
12.如果出现归档的gap
查看日志应用情况:
select THREAD#,sequence#,applied from v$archived_log where THREAD#='2' order by sequence#;
select THREAD#,sequence#,applied from v$archived_log where THREAD#='1' order by sequence#;
select THREAD#,sequence#,applied from v$archived_log where applied='YES' and THREAD#='2' order by sequence#
standby启用实时同步
alter database recover managed standby database using current logfile disconnect;
alter database recover managed standby database cancel;
alter database open read only;
alter database recover managed standby database using current logfile disconnect;
查看日志gap
select * from v$archive_gap;
查看备份中是否有对应的归档文件:
list backup of archivelog from logseq=75358 until logseq=75392 thread=1;
如果出现gap,可以用如下方式处理:
1.如果主库有备份,归档已经被备份并且现在没有保留在主库的归档目录下:
可以直接在主库或者备库使用下面的命令执行恢复操作,将归档恢复
(1)注册备份集:
list backupset of database;
catalog start with '/bak/'; 或者 CATALOG DEVICE TYPE 'SBT_TAPE' BACKUPPIECE '/tmp/backup'
或者:catalog backuppiece '/tmp/backup'
(2)恢复归档:
#! /bin/bash
/oracle/app/oracle/product/11.2.0/db/bin/rman target / <<EOF
run {
ALLOCATE CHANNEL c0 TYPE 'SBT_TAPE' SEND 'NB_ORA_SERV=NBUmaster,NB_ORA_CLIENT=yymhdb1,NB_ORA_DISK_MEDIA_SERVER=nbu5230j5';
ALLOCATE CHANNEL c1 TYPE 'SBT_TAPE' SEND 'NB_ORA_SERV=NBUmaster,NB_ORA_CLIENT=yymhdb2,NB_ORA_DISK_MEDIA_SERVER=nbu5230j5';
restore archivelog from logseq=69653 until logseq=69677 thread=2;
RELEASE CHANNEL c0;
RELEASE CHANNEL c2;
}
(3)如果在备库恢复的归档,则还需要注册归档:
注册归档:CATALOG ARCHIVELOG '+FRA/archivelog/arc_ecdbpr_2_31129_928378592.arc';
2.因为造成归档gap的根本原因是控制文件不够新,控制文件中没有记录对应的归档信息,所以我们可以在备库控制文件中注册对应的归档信息,或者保证拿到最新的控制文件,(主库启动到mount下)
3.可以在主库将归档拷贝到备库
13.如果temp 默认不在oracle安装目录下,并且没有配置db_file_name_convert而导致数据库异常停止,并找不到对应的tempfile的数据文件而报错:
查看tempfile的配置:
select tablespace_name, file_id, file_name,status,autoextensible, round(bytes/(1024*1024),0) total_space from dba_temp_files order by tablespace_name,file_name;
删除旧的tempfile配置:
alter database tempfile '+data/yymh/tempfile/temp01.dbf' drop;
新增tempfile:
alter tablespace temp add tempfile '/data/yymh/tempfile/temp.262.887397719' size 8782k reuse;
14 .同步状态验证:
通过以下sql检查验证同步情况 select name,open_mode,DATABASE_ROLE,PROTECTION_MODE,PROTECTION_LEVEL from v$database; 查看日志应用情况: select THREAD#,sequence#,applied from v$archived_log where THREAD#='2' order by sequence#; select THREAD#,sequence#,applied from v$archived_log where THREAD#='1' order by sequence#; 查看备库进程情况 select process,status,sequence# from v$managed_standby; RFS进程:负责日志的传输 MRP进程:负责日志的应用 针对RAC环境的dg环境,RFS和MRP是只存在一个节点中的。 如果登录一个节点发现没有这两个进程,要在另一个节点上再次验证。 查看备库数据库同步情况: select thread#,sequence#,applied from v$archived_log; 查看applied的结果,如果是YES 最后为IN-MEMORY 表示数据已经应用。 如果 结果中出现NO,表示数据同步已经出现延迟,要明确是未来得及应用还是同步中断。
15. oracle汇总快速查看错误日志的命令:
oerr ora 01187 oerr ora 471 929 cd /oracle/app/oracle/diag/rdbms/yymh_std/yymh/trace/ 930 ls -ltr *dbw* 931 tail -200 yymh_dbw0_1746.trc
16. oracle的异常bug:
处理如下bug,只需要在将备库启动到mount,在启用日志同步即可
Slave exiting with ORA-600 exception Errors in file /oracle/app/oracle/diag/rdbms/yymh_std/yymh/trace/yymh_pr03_14316.trc: ORA-00600: internal error code, arguments: [kcbr_apply_change_11], [], [], [], [], [], [], [], [], [], [], [] Slave exiting with ORA-600 exception Errors in file /oracle/app/oracle/diag/rdbms/yymh_std/yymh/trace/yymh_pr02_14314.trc: ORA-00600: internal error code, arguments: [kcbr_apply_change_11], [], [], [], [], [], [], [], [], [], [], []
配置完毕!