您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么搭建oracle DataGuard”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
1.備庫環(huán)境變量
復(fù)制主庫環(huán)境變量一致即可,注意sid,$ORACLE_BASE,$ORACLE_HOME
2.軟件及補(bǔ)丁
主庫查看補(bǔ)丁版本
select COMMENTS from dba_registry_history;
或opatch lsinv
mkdir /u01/oracle/software
cd /u01/oracle/software
注意:所有7u4的系統(tǒng)都要下載這個(gè)補(bǔ)丁包
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 <數(shù)據(jù)庫安裝包>
get p13390677_112040_Linux-x86-64_2of7.zip <數(shù)據(jù)庫安裝包>
get p6880880_112000_Linux-x86-64.zip <補(bǔ)丁安裝器OPatch包>
get <補(bǔ)丁版本>
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 <補(bǔ)丁版本>
cd database
xclock
./runInstaller
跑腳本
Finish
cd ..
mv $ORACLE_HOME/OPatch/ $ORACLE_HOME/OPatch.bak
mv /u01/oracle/software/OPatch/ $ORACLE_HOME/
打補(bǔ)丁必須要有環(huán)境變量
cd 19692824
opatch apply
cd ..
cd <補(bǔ)丁版本>
opatch apply (如果不能打補(bǔ)丁,查看監(jiān)聽是否為關(guān)閉狀態(tài))
opatch lsinv
3.主庫參數(shù)檢查
檢查主備庫cpu,內(nèi)存和文件系統(tǒng)
備庫盡量和主庫一致
free -g
lscpu
df -h
主庫參數(shù)檢查(保證歸檔和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;
主庫參數(shù)檢查(datafile是否都是online狀態(tài)或system狀態(tài))
select distinct status from v$datafile;
主庫參數(shù)檢查 (表空間是否都是online狀態(tài))
select distinct STATUS from dba_tablespaces;
主庫參數(shù)檢查(都是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
如果主庫已經(jīng)有了一個(gè)dg庫的話,就要注意<sid>_sec變量名字要改成不沖突的名字
log_archive_dest_2參數(shù)要改成不沖突的通道
二.操作步驟
1.主庫(備庫相同)配置tnsnames.ora
vi $ORACLE_HOME/network/admin/tnsnames.ora
<sid> =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <主庫IP>)(PORT = <主庫端口>))
)
(CONNECT_DATA =
(SERVICE_NAME = <sid>)
)
)
<sid>_sec =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <備庫IP>)(PORT = <備庫端口>))
)
(CONNECT_DATA =
(SERVICE_NAME = <sid>)
)
)
2.備庫的listener.ora和sqlnet.ora
vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_<sid> =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = <sid>)
(ORACLE_HOME = /u01/oracle/product/db11gr2)
(SID_NAME = <sid>)
)
)
<sid> =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = <備庫IP>)(PORT = <備庫端口>))
)
ADR_BASE_<sid> = /u01/oracle
INBOUND_CONNECT_TIMEOUT_<sid>=60
SECURE_REGISTER_<sid> = (TCP)
ADMIN_RESTRICTIONS_<sid> =ON
DIAG_ADR_ENABLED_<sid> = ON
vi $ORACLE_HOME/network/admin/sqlnet.ora
SQLNET.INBOUND_CONNECT_TIMEOUT =60
sqlnet.expire_time =10
sqlnet.allow_logon_version =8
DIAG_ADR_ENABLED_<sid> =ON
lsnrctl start <sid>
主備庫
tnsping <sid>
tnsping <sid>_sec
3.主庫傳輸必要文件(密碼文件,參數(shù)文件,控制文件)
export ORACLE_SID=<sid>
sqlplus / as sysdba
create pfile='/tmp/init<sid>.ora' from spfile;
exit
scp $ORACLE_HOME/dbs/orapw<sid> <備庫IP>:/home/oracle
scp /tmp/init<sid>.ora <備庫IP>:/tmp
scp /usr/openv/scripts/<sid>_controlfile.ctl <備庫IP>:/tmp
備庫執(zhí)行
mv /home/oracle/orapw<sid> $ORACLE_HOME/dbs
4.修改參數(shù),啟動(dòng)到mount
修改參數(shù)文件:
如果是遷移用的dg庫則不要修改參數(shù)文件
如果是單純的dg庫則按照備庫的實(shí)際內(nèi)存等修改
一般來說修改歸檔路徑,fal_server和fal_client,創(chuàng)建歸檔文件和審計(jì)文件路徑
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結(jié)尾)
*.pga_aggregate_target=2147483648 #修改大小
*.sga_max_size=12884901888 #修改大小
*.shared_pool_size=1073741824 #修改大小
*.utl_file_dir='/oraarchivelog/xmata' #修改目錄
啟動(dòng)到nomount,修改參數(shù)
export ORACLE_SID=<sid>
sqlplus / as sysdba
create spfile from pfile='/tmp/init<sid>.ora';
startup nomount;
alter system set standby_file_management=auto; #主庫添加數(shù)據(jù)文件時(shí),dg庫自動(dòng)添加
alter system set filesystemio_options=setall scope=spfile; #設(shè)置異步IO
alter system set parallel_execution_message_size=32768 scope=spfile; #并行執(zhí)行消息大小,遷移用的不要設(shè)置此參數(shù)
exit
啟動(dòng)到mount
rman target /
restore controlfile from '/tmp/<sid>_controlfile.ctl';
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壓縮參數(shù)
alter system set log_archive_dest_2='service=<sid>_sec LGWR ASYNC NOAFFIRM NET_TIMEOUT=30';
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_<SID>/
cd /home/oracle/scripts_<SID>/
vi dg_rm_applied_arclog.sh (修改腳本sid,$ORACLE_HOME,$ORACLE_BASE)
##########DG搭建的部署自動(dòng)刪除歸檔日志的定時(shí)任務(wù)##########
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/oracle/product/db11gr2
export ORACLE_SID=<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" <<EOF
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 / <<EOF
delete noprompt force archivelog until sequence ${SEQ1} thread 1;
exit;
EOF
######if PRIMARY is RAC, delete archivelog tread 2
SEQ2=`sqlplus -s "/ as sysdba" <<EOF
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 / <<EOF
delete noprompt force archivelog until sequence ${SEQ2} thread 2;
exit;
EOF
fi
crontab -e
0 * * * * sh /home/oracle/scripts_<SID>/dg_rm_applied_arclog.sh >/dev/null 2>&1
crontab -l
6.磁帶庫方式恢復(fù)
配置恢復(fù)腳本(17:00之后才能發(fā)起)
***********************************************************************************************************
如果主備庫文件系統(tǒng)一致,則忽略此操作
如果主備庫文件系統(tǒng)不一致,在主庫執(zhí)行以下語句后在備庫修改成備庫路徑,粘貼到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 '||''''||'目標(biāo)端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 #主庫主機(jī)名查詢
備庫恢復(fù)腳本:
mkdir /home/oracle/rman_<sid>
cd /home/oracle/rman_<sid>
vi res.sh
DATE=`date +%Y%m%d%H`
export ORACLE_SID=<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=<主庫主機(jī)名>)';
ALLOCATE CHANNEL ch01 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主庫主機(jī)名>)';
ALLOCATE CHANNEL ch02 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主庫主機(jī)名>)';
ALLOCATE CHANNEL ch03 TYPE 'SBT_TAPE' parms 'ENV=(NB_ORA_CLIENT=<主庫主機(jī)名>)';
restore database;
recover database delete archivelog;
release channel ch00;
release channel ch01;
release channel ch02;
release channel ch03;
}
nohup sh res.sh &
*************************************************************************************************************************
如果是數(shù)據(jù)量很小的新庫 可以用此方式恢復(fù)
6.主庫duplicate發(fā)起恢復(fù)(17:00之后才能發(fā)起)
DG啟動(dòng)到nomount模式發(fā)起(主庫或dg庫做都可以)
rman target sys/<主庫sys密碼>@<sid> auxiliary sys/<主庫sys密碼>@<sid>_sec nocatalog
duplicate target database for standby from active database dorecover nofilenamecheck;
*************************************************************************************************************************
*************************************************************************************************************************
6.主庫壓縮全備方式恢復(fù)
進(jìn)行全庫壓縮備份
mkdir /<sid>/db_dg_arc/<sid>/rman
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 '/<sid>/db_dg_arc/<sid>/rman/bk_%d_%T_%U';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
vi rman_backup.sh
export ORACLE_SID=<sid>
rman nocatalog target / cmdfile=backup.sql msglog=backup.log
nohup sh rman_backup.sh &
后臺(tái)執(zhí)行開始全庫壓縮,注意目錄空間是否足夠存放全備份集
備份完畢后把備份片傳輸?shù)匠啥紝?duì)應(yīng)的目錄下
DG
mkdir -p /<sid>/db_dg_arc/<sid>/rman
主庫
scp bk* <備庫IP>:/<sid>/db_dg_arc/<sid>/rman/
備庫進(jìn)行全庫恢復(fù)
cd /<sid>/db_dg_arc/<sid>/rman/
rman target /
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
catalog start with '/<sid>/db_dg_arc/<sid>/rman/';
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=<sid>
rman nocatalog target / cmdfile=recover.sql msglog=recover.log
nohup sh rman_recover.sh &
cd /<sid>/db_dg_arc/<sid>
rm -rf rman
*************************************************************************************************************************
7.恢復(fù)后配置
*************************************************************************************************************************
文件系統(tǒng)不一致的需要重命名redolog(dg庫需要為mount狀態(tài),取消日志應(yīng)用)
select member from v$logfile; #主庫查詢出目前redo日志的名字
rename文件系統(tǒng):
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;
#添加路徑轉(zhuǎn)換參數(shù):(主庫新增數(shù)據(jù)文件,備庫可以通過該參數(shù)自動(dòng)轉(zhuǎn)換文件名)
**************************************************************************************************************************
在備機(jī)上創(chuàng)建standby logfile(遷移用的dg庫不用創(chuàng)建這步)
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多一組,每組只能創(chuàng)建一個(gè)成員,group編號(hào)不能重復(fù),group編號(hào)要比主庫上最大group#大于20
ALTER DATABASE ADD STANDBY LOGFILE group 30 ('/<rdo路徑>/stdredo30.log') SIZE <和主庫一樣大小>;
......
主庫重啟通道(不重啟查詢同步時(shí)間報(bào)錯(cuò))
sqlplus / as sysdba
alter system set log_archive_dest_state_2=defer;
alter system set log_archive_dest_state_2=enable;
備庫
show parameter fal #沒有的話設(shè)置一下
alter system set fal_server='<sid>';
alter system set fal_client='<sid>_sec';
show parameter fal
shu immediate
startup nomount
alter database mount;
show parameter convert
8.應(yīng)用日志
alter database open read only;
(不報(bào)錯(cuò)直接執(zhí)行,如果沒有standby redo就不用加using current logfile)
alter database recover managed standby database using current logfile disconnect from session;
(如果報(bào)錯(cuò)執(zhí)行以下四步,如果沒有standby redo就不用加using current logfile)
alter database recover managed standby database disconnect from session; #應(yīng)用到最新日志,可能會(huì)很長時(shí)間,可能有g(shù)ap
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”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。