十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本篇内容介绍了“怎么搭建oracle DataGuard”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
成都创新互联公司从2013年成立,是专业互联网技术服务公司,拥有项目网站建设、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元下冶做网站,已为上家服务,为下冶各地企业和个人服务,联系电话:18980820575
1.备库环境变量
复制主库环境变量一致即可,注意sid,$ORACLE_BASE,$ORACLE_HOME
2.软件及补丁
主库查看补丁版本
select COMMENTS from dba_registry_history;
或opatch lsinv
mkdir /u01/oracle/software
cd /u01/oracle/software
注意:所有7u4的系统都要下载这个补丁包
get software/oracle/db/PSU171017/p19692824_112040_Linux-x86-64.zip
sftp
sftp> cd software/oracle/db
get p13390677_112040_Linux-x86-64_1of7.zip <数据库安装包>
get p13390677_112040_Linux-x86-64_2of7.zip <数据库安装包>
get p6880880_112000_Linux-x86-64.zip <补丁安装器OPatch包>
get <补丁版本>
bye
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip
unzip p6880880_112000_Linux-x86-64.zip
unzip p19692824_112040_Linux-x86-64.zip
unzip <补丁版本>
cd database
xclock
./runInstaller
跑脚本
Finish
cd ..
mv $ORACLE_HOME/OPatch/ $ORACLE_HOME/OPatch.bak
mv /u01/oracle/software/OPatch/ $ORACLE_HOME/
打补丁必须要有环境变量
cd 19692824
opatch apply
cd ..
cd <补丁版本>
opatch apply (如果不能打补丁,查看监听是否为关闭状态)
opatch lsinv
3.主库参数检查
检查主备库cpu,内存和文件系统
备库尽量和主库一致
free -g
lscpu
df -h
主库参数检查(保证归档和force logging开启)
set line 200
col DATABASE_ROLE for a30
col DB_UNIQUE_NAME for a20
col OPEN_MODE for a30
col LOG_MODE for a30
select database_role,db_unique_name,open_mode,log_mode,force_logging from v$database;
主库参数检查(datafile是否都是online状态或system状态)
select distinct status from v$datafile;
主库参数检查 (表空间是否都是online状态)
select distinct STATUS from dba_tablespaces;
主库参数检查(都是FULL)
show parameter DB_BLOCK_CHECKING;
show parameter DB_LOST_WRITE_PROTECT;
show parameter DB_BLOCK_CHECKSUM;
如果不是的话查看是修改是否需要重启,不需要就修改
alter system set DB_BLOCK_CHECKING='FULL';
alter system set DB_LOST_WRITE_PROTECT ='FULL';
alter system set DB_BLOCK_CHECKSUM ='FULL';
主库通道检查
set linesize 200 pages 999
col dest_id for 9999
col dest_name for a30
col status for a10
col error for a50
select dest_id,dest_name,status,error from v$archive_dest;
show parameter dest
exit
如果主库已经有了一个dg库的话,就要注意
log_archive_dest_2参数要改成不冲突的通道
二.操作步骤
1.主库(备库相同)配置tnsnames.ora
vi $ORACLE_HOME/network/admin/tnsnames.ora
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <主库IP>)(PORT = <主库端口>))
)
(CONNECT_DATA =
(SERVICE_NAME =
)
)
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <备库IP>)(PORT = <备库端口>))
)
(CONNECT_DATA =
(SERVICE_NAME =
)
)
2.备库的listener.ora和sqlnet.ora
vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME =
(ORACLE_HOME = /u01/oracle/product/db11gr2)
(SID_NAME =
)
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = <备库IP>)(PORT = <备库端口>))
)
ADR_BASE_
INBOUND_CONNECT_TIMEOUT_
SECURE_REGISTER_
ADMIN_RESTRICTIONS_
DIAG_ADR_ENABLED_
vi $ORACLE_HOME/network/admin/sqlnet.ora
SQLNET.INBOUND_CONNECT_TIMEOUT =60
sqlnet.expire_time =10
sqlnet.allow_logon_version =8
DIAG_ADR_ENABLED_
lsnrctl start
主备库
tnsping
tnsping
3.主库传输必要文件(密码文件,参数文件,控制文件)
export ORACLE_SID=
sqlplus / as sysdba
create pfile='/tmp/init
exit
scp $ORACLE_HOME/dbs/orapw
scp /tmp/init
scp /usr/openv/scripts/
备库执行
mv /home/oracle/orapw
4.修改参数,启动到mount
修改参数文件:
如果是迁移用的dg库则不要修改参数文件
如果是单纯的dg库则按照备库的实际内存等修改
一般来说修改归档路径,fal_server和fal_client,创建归档文件和审计文件路径
xmata.__oracle_base='/u01/oracle'#ORACLE_BASE set from environment #修改目录
*.audit_file_dest='/db_audit_file_dest/xmata' #修改目录
*.control_files='/xmata/xmatasys_u01/xmata/control01.ctl','/xmata/xmatardo_u01/xmata/control02.ctl','/xmata/xmataudo_u01/xmata/control03.ctl' #修改目录
*.db_cache_size=4294967296 #修改大小
*.diagnostic_dest='/u01/oracle' #修改目录
*.fal_client='xmata_new' #修改名字client端是自己
*.fal_server='xmata' #修改名字
*.java_pool_size=134217728 #修改大小
*.large_pool_size=268435456 #修改大小
*.log_archive_dest_1='LOCATION=/oraarchivelog/xmata' #修改目录
*.log_archive_dest_2='service=zdhdb_sec LGWR ASYNC NOAFFIRM NET_TIMEOUT=30' #删除本行
*.log_archive_format='%t_%s_%r.arc' #添加本行(使归档文件以.arc结尾)
*.pga_aggregate_target=2147483648 #修改大小
*.sga_max_size=12884901888 #修改大小
*.shared_pool_size=1073741824 #修改大小
*.utl_file_dir='/oraarchivelog/xmata' #修改目录
启动到nomount,修改参数
export ORACLE_SID=
sqlplus / as sysdba
create spfile from pfile='/tmp/init
startup nomount;
alter system set standby_file_management=auto; #主库添加数据文件时,dg库自动添加
alter system set filesystemio_options=setall scope=spfile; #设置异步IO
alter system set parallel_execution_message_size=32768 scope=spfile; #并行执行消息大小,迁移用的不要设置此参数
exit
启动到mount
rman target /
restore controlfile from '/tmp/
exit
sqlplus / as sysdba
alter database mount;
alter database create standby controlfile as '/tmp/control01.ctl';
shutdown immediate;
startup nomount;
exit
rman target /
restore controlfile from '/tmp/control01.ctl';
exit
sqlplus / as sysdba
alter database mount;
exit
5.主库配置日志传输通道,备库部署自删除脚本
主库配置日志传输通道
COMPRESSION=enable压缩参数
alter system set log_archive_dest_2='service=
alter system set log_archive_dest_state_2='enable';
col dest_name format a30
select DEST_ID,DEST_NAME,STATUS,error from v$archive_dest_status;
备库部署自删除脚本
mkdir -p /home/oracle/scripts_
cd /home/oracle/scripts_
vi dg_rm_applied_arclog.sh (修改脚本sid,$ORACLE_HOME,$ORACLE_BASE)
##########DG搭建的部署自动删除归档日志的定时任务##########
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/oracle/product/db11gr2
export ORACLE_SID=
export ORACLE_TERM=xterm
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORA_NLS10=$ORACLE_HOME/nls/data
export LIBPATH=$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export LD_LIBRARY_PATH=$ORACLE_HOME/lib32:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib:$ORACLE_HOME/RDBMS/lib:/lib:/usr/lib
export JAVA_HOME=$ORACLE_HOME/jdk
export ORACLE_DOC=$ORACLE_HOME/doc
export SQLPATH=$ORACLE_HOME/dbs
export PATH=$ORACLE_HOME/OPatch:$ORACLE_HOME/bin:$JAVA_HOME/bin:$PATH:/usr/vacpp/bin:/usr/ccs/bin
export CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib
export TMP=/tmp
export TMPDIR=$TMP
export NLS_DATE_FORMAT='yyyy-mm-dd hh34:mi:ss'
export NLS_TIMESTAMP_FORMAT='yyyy-mm-dd hh34:mi:ss.ff'
export NLS_TIMESTAMP_TZ_FORMAT='yyyy-mm-dd hh34:mi:ss.ff'
export EDITOR=vi
stty erase ^H
######delete archivelog tread 1
SEQ1=`sqlplus -s "/ as sysdba" < set heading off feedback off pagesize 0 verify off echo off numwidth 9 select max(SEQUENCE#) from v\\\$archived_log al where al.first_time<=sysdate-1/2 and al.first_time>=sysdate-7 and al.first_time<(select min(checkpoint_time) from v\\\$datafile_header)-1/48 and al.APPLIED='YES' and al.deleted='NO' and al.THREAD#=1; exit; EOF` echo 'DELETE ARC BEFORE' $SEQ1 `date` > rm_thread1.log rman target / < delete noprompt force archivelog until sequence ${SEQ1} thread 1; exit; EOF ######if PRIMARY is RAC, delete archivelog tread 2 SEQ2=`sqlplus -s "/ as sysdba" < set heading off feedback off pagesize 0 verify off echo off numwidth 9 select max(SEQUENCE#) from v\\\$archived_log al where al.first_time<=sysdate-1/2 and al.first_time>=sysdate-7 and al.first_time<(select min(checkpoint_time) from v\\\$datafile_header)-1/48 and al.APPLIED='YES' and al.deleted='NO' and al.THREAD#=2; exit; EOF` echo 'DELETE ARC BEFORE' $SEQ2 `date` > rm_thread2.log if [ ! -n "$SEQ2" ];then exit 0; else rman target / < delete noprompt force archivelog until sequence ${SEQ2} thread 2; exit; EOF fi crontab -e 0 * * * * sh /home/oracle/scripts_ crontab -l 6.磁带库方式恢复 配置恢复脚本(17:00之后才能发起) *********************************************************************************************************** 如果主备库文件系统一致,则忽略此操作 如果主备库文件系统不一致,在主库执行以下语句后在备库修改成备库路径,粘贴到res.rcv脚本中restore前 select 'set newname for datafile '||file#||' to '||''''||'' || '/' || 'datafiletihuanlujing' ||'/' || substr(name,instr(name,'/',1,3)+1)||''''||';' from v$datafile union all select 'set newname for tempfile '||file#||' to '||''''||'' || '/' || 'temptihuanlujing' ||'/' || substr(name,instr(name,'/',1,3)+1)||''''||';' from v$tempfile; 或者 select 'alter database rename file '||file_name||' to '||''''||'目标端data路径' || '/' || substr(file_name,instr(file_name,'/',1,3)+1)||''''||';' from dba_data_files; 如下语句粘贴到res.rcv脚本中restore后recover前 switch datafile all; *********************************************************************************************************** grep CLIENT_NAME /usr/openv/netbackup/bp.conf #主库主机名查询 备库恢复脚本: mkdir /home/oracle/rman_ cd /home/oracle/rman_ vi res.sh DATE=`date +%Y%m%d%H` export ORACLE_SID= rman nocatalog target / cmdfile=res.rcv msglog=res.log.$DATE vi res.rcv run{ ALLOCATE CHANNEL ch00 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主库主机名>)'; ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主库主机名>)'; ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主库主机名>)'; ALLOCATE CHANNEL ch03 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主库主机名>)'; restore database; recover database delete archivelog; release channel ch00; release channel ch01; release channel ch02; release channel ch03; } nohup sh res.sh & ************************************************************************************************************************* 如果是数据量很小的新库 可以用此方式恢复 6.主库duplicate发起恢复(17:00之后才能发起) DG启动到nomount模式发起(主库或dg库做都可以) rman target sys/<主库sys密码>@ duplicate target database for standby from active database dorecover nofilenamecheck; ************************************************************************************************************************* ************************************************************************************************************************* 6.主库压缩全备方式恢复 进行全库压缩备份 mkdir / cd !$ vi backup.sql run { allocate channel c1 type disk maxpiecesize 10G; allocate channel c2 type disk maxpiecesize 10G; allocate channel c3 type disk maxpiecesize 10G; allocate channel c4 type disk maxpiecesize 10G; backup as compressed backupset database format '/ release channel c1; release channel c2; release channel c3; release channel c4; } vi rman_backup.sh export ORACLE_SID= rman nocatalog target / cmdfile=backup.sql msglog=backup.log nohup sh rman_backup.sh & 后台执行开始全库压缩,注意目录空间是否足够存放全备份集 备份完毕后把备份片传输到成都对应的目录下 DG mkdir -p / 主库 scp bk* <备库IP>:/ 备库进行全库恢复 cd / rman target / CONFIGURE DEFAULT DEVICE TYPE TO DISK; catalog start with '/ exit vi recover.sql run { allocate channel c1 type disk maxpiecesize 10G; allocate channel c2 type disk maxpiecesize 10G; allocate channel c3 type disk maxpiecesize 10G; allocate channel c4 type disk maxpiecesize 10G; restore database; recover database; release channel c1; release channel c2; release channel c3; release channel c4; } vi rman_recover.sh export ORACLE_SID= rman nocatalog target / cmdfile=recover.sql msglog=recover.log nohup sh rman_recover.sh & cd / rm -rf rman ************************************************************************************************************************* 7.恢复后配置 ************************************************************************************************************************* 文件系统不一致的需要重命名redolog(dg库需要为mount状态,取消日志应用) select member from v$logfile; #主库查询出目前redo日志的名字 rename文件系统: show parameter standby_file_management alter system set standby_file_management=manual; alter database rename file '+DATA/zdhdb/onlinelog/group_1.257.876509499' to '/zdhdb/zdhdbrdo_u01/zdhdb/redo01'; ...... alter system set standby_file_management=auto; show parameter convert alter system set log_file_name_convert='+DATA/zdhdb/onlinelog','/zdhdb/zdhdbrdo_u01/zdhdb' scope=spfile; alter system set db_file_name_convert='+DATA/zdhdb/datafile','/zdhdb/zdhdbdata_u01/zdhdb','+DATA01/zdhdb/datafile','/zdhdb/zdhdbdata_u01/zdhdb' scope=spfile; #添加路径转换参数:(主库新增数据文件,备库可以通过该参数自动转换文件名) ************************************************************************************************************************** 在备机上创建standby logfile(迁移用的dg库不用创建这步) set pagesize 2000 set linesize 150 col member for a50 col status for a20 select g.group#, g.thread#,g.status,f.member, g.members, g.bytes/1024/1024 MB,g.sequence# from v$log g, v$logfile f where g.group#=f.group# order by 1; #主库查看redo日志路径及大小 standby logfile需要比redologfile多一组,每组只能创建一个成员,group编号不能重复,group编号要比主库上最大group#大于20 ALTER DATABASE ADD STANDBY LOGFILE group 30 ('/ ...... 主库重启通道(不重启查询同步时间报错) sqlplus / as sysdba alter system set log_archive_dest_state_2=defer; alter system set log_archive_dest_state_2=enable; 备库 show parameter fal #没有的话设置一下 alter system set fal_server=' alter system set fal_client=' show parameter fal shu immediate startup nomount alter database mount; show parameter convert 8.应用日志 alter database open read only; (不报错直接执行,如果没有standby redo就不用加using current logfile) alter database recover managed standby database using current logfile disconnect from session; (如果报错执行以下四步,如果没有standby redo就不用加using current logfile) alter database recover managed standby database disconnect from session; #应用到最新日志,可能会很长时间,可能有gap alter database recover managed standby database cancel; alter database open read only ; alter database recover managed standby database using current logfile disconnect from session; “怎么搭建oracle DataGuard”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
文章题目:怎么搭建oracleDataGuard
网站网址:http://shouzuofang.com/article/jepjdp.html