溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

oracle data guard 11.0.2.4

發(fā)布時(shí)間:2020-07-24 12:07:53 來(lái)源:網(wǎng)絡(luò) 閱讀:518 作者:涼了涼了 欄目:關(guān)系型數(shù)據(jù)庫(kù)

    Oracle DataGuard是Oracle自帶的數(shù)據(jù)同步功能,基本原理是將日志文件從原數(shù)據(jù)庫(kù)傳輸?shù)侥繕?biāo)數(shù)據(jù)庫(kù),然后在目標(biāo)數(shù)據(jù)庫(kù)上應(yīng)用這些日志文件,從而使目標(biāo)數(shù)據(jù)庫(kù)與源數(shù)據(jù)庫(kù)保持同步,是一種數(shù)據(jù)庫(kù)級(jí)別的高可用性方案。

oracle dg 搭建方法兩種:

    1.DB停機(jī),拷貝所以文件到DG庫(kù),影響業(yè)務(wù)

    2.DB不停機(jī),rman熱備方式拷貝到DG庫(kù),不影響業(yè)務(wù)。

oracle dg 模式三種:

    1.最大保護(hù) 
    這種模式是默認(rèn)的數(shù)據(jù)保護(hù)模式,在不影響源數(shù)據(jù)庫(kù)性能的條件下提供盡可能高的數(shù)     
據(jù)保護(hù)等級(jí)。在該種模式下,一旦日志數(shù)據(jù)寫(xiě)到源數(shù)據(jù)庫(kù)的聯(lián)機(jī)日志文件,事務(wù)即可提交,不必等待日志寫(xiě)到目標(biāo)數(shù)據(jù)庫(kù),如果網(wǎng)絡(luò)帶寬充足,該種模式可提供類似于最大可用模式的數(shù)據(jù)保護(hù)等級(jí)。 
    2.最大可用性 
這種模式和”最大保護(hù)”基本上差不多。正常情況下,主備庫(kù)之間是同步的。 
當(dāng)網(wǎng)絡(luò)或者備庫(kù)出現(xiàn)問(wèn)題時(shí),不會(huì)影響到主庫(kù)的當(dāng)機(jī),主庫(kù)會(huì)自動(dòng)轉(zhuǎn)換庫(kù)”最大性能”模式,等待備庫(kù)可用時(shí),將歸檔傳輸?shù)絺鋷?kù)做恢復(fù)。 
    3.最大性能 
這種模式保證主庫(kù)性能最大化,主備庫(kù)之間數(shù)據(jù)是異步傳輸?shù)?。即,主備日志歸檔以 
后才會(huì)傳輸?shù)絺溆脦?kù),在備庫(kù)上使用歸檔日志文件做恢復(fù)操作。



熱備方式搭建DG庫(kù):

主庫(kù)配置:

startup mount;

開(kāi)啟歸檔:

alter database archivelog;

開(kāi)啟強(qiáng)制歸檔force logging(默認(rèn)0秒):

alter database force logging; 

開(kāi)啟閃回(前提開(kāi)啟歸檔):

設(shè)置閃回區(qū)大?。?alter system set db_recovery_file_dest_size='5G'; 

設(shè)置閃回區(qū)目錄:#alter system set db_recovery_file_dest='/data/db_recovery_file_dest/';

開(kāi)啟閃回:alter database flashback on; 



#設(shè)置歸檔日志,默認(rèn)位置 USE_DB_RECOVERY_FILE_DEST,查詢位置show parameter DB_RECOVERY_FILE_DEST  :

#alter system set  log_archive_dest_1='location=/data/JINGYU/archivelog';


#設(shè)置強(qiáng)制歸檔時(shí)間為30分鐘:

#alter system set archive_lag_target=1800;


查看是否開(kāi)啟:

archive log list;

select  FLASHBACK_ON    from v$database;

select force_logging from v$database;


添加STANDBY 日志文件:

查詢主庫(kù)在線日志的大小和組數(shù):

select group#,bytes/1024/1024 from v$log;

查詢備庫(kù)在線日志的大小和組數(shù):

select group#,bytes/1024/1024 from v$standby_log;

創(chuàng)建standby logfile(主庫(kù)log+1)

alter database add standby logfile group 4 '/data/zy/onlinelog/redo11_stb01.log' size 50M;

alter database add standby logfile group 5 '/data/zy/onlinelog/redo11_stb02.log' size 50M;

alter database add standby logfile group 6 '/data/zy/onlinelog/redo11_stb03.log' size 50M;

alter database add standby logfile group 7 '/data/zy/onlinelog/redo11_stb04.log' size 50M;


參數(shù)文件修改:

cat >> alterspfile.sql <<EOF

alter system set log_archive_config='DG_CONFIG=(primary,standby)';

alter system set log_archive_dest_2='SERVICE=standby arch   VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=standby' scope=spfile;

alter system set log_archive_dest_state_1='enable';

alter system set log_archive_dest_state_2='enable';

alter system set db_file_name_convert='/data/zy/datafile','/data/zy/datafile' scope=spfile;

alter system set log_file_name_convert='/data/zy/onlinelog','/data/zy/onlinelog' scope=spfile;

alter system set fal_client='primary';

alter system set fal_server='standby';

alter system set standby_file_management='AUTO';

EOF


mkdir /data/zy/onlinelog /data/zy/datafile  -p

chown oracle.oinstall /data/zy/onlinelog /data/zy/datafile -R


shutdown immediate

startup


配置監(jiān)聽(tīng),TNS文件:

動(dòng)態(tài):listener.ora--測(cè)試數(shù)據(jù)庫(kù)啟動(dòng)到nomount狀態(tài)監(jiān)聽(tīng)

LISTENER=(DESCRIPTION_LIST=(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))))

ADR_BASE_LISTENER=/u01/app/oracle


靜態(tài):listener.ora


SID_LIST_LISTENER=(SID_LIST=(SID_DESC=(GLOBAL_DBNAME=zy)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)(SID_NAME=jingyu)))


TNS文件配置:tnsnames.ora--類似hosts,指定實(shí)例名與IP解析

primary=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.64.50)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))

standby=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.64.60)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))


lsnrctl stop ; lsnrctl start ;


創(chuàng)建pfile并拷貝到standby

create pfile='/tmp/initzy.ora' from spfile;

scp /tmp/initzy.ora 2.2.2.11:/u01/app/oracle/product/11.2.0/dbhome_1/dbs

拷貝密碼文件到standby

scp orapwjingyu 2.2.2.11:/u01/app/oracle/product/11.2.0/dbhome_1/dbs



備庫(kù)配置:


修改pfile文件:

*.fal_client='standby'

*.fal_server='primary'


*.log_archive_dest_2='SERVICE=primary VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=primary'




#修改密碼文件


#mv orapwjingyu orapwjingyus


創(chuàng)建pfile配置里相應(yīng)文件夾


mkdir -p /u01/app/oracle/admin/zy/adump


mkdir -p /u01/app/oracle/oradata/zy/


mkdir -p /u01/app/oracle/fast_recovery_area/zy/


mkdir -p /data/zy/datafile


mkdir -p /u01/app/oracle/fast_recovery_area


mkdir -p /data/zy/onlinelog


chown oracle.oinstall  /u01/app/oracle/admin/zy/adump /u01/app/oracle/oradata/zy/  /u01/app/oracle/fast_recovery_area/zy/ /data/zy/datafile /u01/app/oracle/fast_recovery_area /data/zy/onlinelog






修改監(jiān)聽(tīng)文件

SID_LIST_LISTENER=(SID_LIST=(SID_DESC=(GLOBAL_DBNAME=zy)(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)(SID_NAME=jingyu)))

LISTENER=(DESCRIPTION_LIST=(DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))))

ADR_BASE_LISTENER = /u01/app/oracle

修改TNS




primary=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.10)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))


standby=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=2.2.2.11)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zy)))


lsnrctl stop ; lsnrctl start ;


啟動(dòng)數(shù)據(jù)庫(kù)到nomount狀態(tài)


startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initjingyus.ora';


create spfile from pfile;   #創(chuàng)建spfile


驗(yàn)證監(jiān)聽(tīng)和TNS配置


tnsping primaryt 


tnsping standby




主備執(zhí)行


sqlplus sys/oracle@primary as sysdba


sqlplus sys/oracle@standby as sysdba


備庫(kù)數(shù)據(jù)恢復(fù):

 rman target sys/oracle@primary auxiliary sys/oracle@standby

     duplicate target database for standby nofilenamecheck dorecover;  

rman>duplicate target database for standby from active database nofilenamecheck;



Finished Duplicate Db at 2018-06-25 xx xx xx  ---------------正常完成.



備庫(kù)開(kāi)啟歸檔,閃回,強(qiáng)制歸檔。

startup nomount

alter database mount standby database;  

alter database archivelog;

alter system set db_recovery_file_dest_size='5G'; 

alter database flashback on;  

alter database open read only;  

alter database recover managed standby database using current logfile disconnect from session;    #開(kāi)啟實(shí)時(shí)同步





驗(yàn)證:

歸檔日志有無(wú)報(bào)錯(cuò)

select dest_name,error from v$archive_dest; 

 查詢主庫(kù)最大歸檔序號(hào)(scn)一致即歸檔同步成功。

select max(sequence#) from v$archived_log;

日志切換

alter system archive log current;

select max(sequence#) from v$archived_log;

創(chuàng)建測(cè)試表:





切換測(cè)試


3.5.1 switchover


switchover是用戶有計(jì)劃的進(jìn)行停機(jī)切換,能夠保證不丟失數(shù)據(jù),下面我們來(lái)看下switchover是怎樣操作的:


主庫(kù)上操作:


select switchover_status,database_role from v$database; 


SWITCHOVER_STATUS    DATABASE_ROLE


-------------------- ----------------


TO STANDBY      PRIMARY


 


SQL>


注意:上面查詢結(jié)果為TO STANDBY 或 SESSIONS ACTIVE表明可以進(jìn)行切換


 


SQL> alter database commit to switchover to physical standby;


 


Databasealtered.


SQL> startup mount


ORACLE instance started.


 


Total System Global Area  688959488 bytes


Fixed Size          2256432 bytes


Variable Size        566231504 bytes


Database Buffers     117440512 bytes


Redo Buffers           3031040 bytes


Database mounted.


SQL> select database_role from v$database;


 


DATABASE_ROLE


----------------


PHYSICAL STANDBY


 


備庫(kù)上操作:


SQL> select switchover_status,database_role from v$database;


 


SWITCHOVER_STATUS    DATABASE_ROLE


------------------------------------


TO PRIMARY       PHYSICAL STANDBY


 


SQL>


注意:上面查詢結(jié)果顯示為TO PRIMARY 或 SESSIONS ACTIVE表明可以切換成主庫(kù);


現(xiàn)在可以把備庫(kù)切換成主庫(kù):


SQL> alter database commit to switchover to primary with session shutdown;


 


Database altered.


 


SQL> alter database open;


 


Database altered.


 


SQL> select switchover_status,database_role,open_mode from v$database;


 


SWITCHOVER_STATUS    DATABASE_ROLE    OPEN_MODE


-------------------- ------------------------------------


SESSIONS ACTIVE      PRIMARY         READ WRITE


 


記住:這時(shí)候需要在現(xiàn)在的備庫(kù)(原先的主庫(kù))開(kāi)啟實(shí)時(shí)同步


 


SQL> alter database open;


 


Database altered.


 


SQL> alter database recover managed standby database using current logfile disconnect from session;


 


Database altered.


 


到此DG switover切換完成,驗(yàn)證方法同上。


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI