您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么搭建oracle DataGuard”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
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庫的話,就要注意<sid>_sec變量名字要改成不沖突的名字
log_archive_dest_2參數要改成不沖突的通道
二.操作步驟
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.主庫傳輸必要文件(密碼文件,參數文件,控制文件)
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
備庫執行
mv /home/oracle/orapw<sid> $ORACLE_HOME/dbs
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=<sid>
sqlplus / as sysdba
create spfile from pfile='/tmp/init<sid>.ora';
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/<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壓縮參數
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搭建的部署自動刪除歸檔日志的定時任務##########
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.磁帶庫方式恢復
配置恢復腳本(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_<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=<主庫主機名>)';
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密碼>@<sid> auxiliary sys/<主庫sys密碼>@<sid>_sec nocatalog
duplicate target database for standby from active database dorecover nofilenamecheck;
*************************************************************************************************************************
*************************************************************************************************************************
6.主庫壓縮全備方式恢復
進行全庫壓縮備份
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 &
后臺執行開始全庫壓縮,注意目錄空間是否足夠存放全備份集
備份完畢后把備份片傳輸到成都對應的目錄下
DG
mkdir -p /<sid>/db_dg_arc/<sid>/rman
主庫
scp bk* <備庫IP>:/<sid>/db_dg_arc/<sid>/rman/
備庫進行全庫恢復
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.恢復后配置
*************************************************************************************************************************
文件系統不一致的需要重命名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 ('/<rdo路徑>/stdredo30.log') SIZE <和主庫一樣大小>;
......
主庫重啟通道(不重啟查詢同步時間報錯)
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='<sid>';
alter system set fal_client='<sid>_sec';
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”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。