您好,登錄后才能下訂單哦!
小編給大家分享一下Oracle如何給rac創(chuàng)建單實(shí)例dg并做主從切換功能,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
一、概述
本文將介紹如何給rac搭建單節(jié)點(diǎn)的dg,以及如何對(duì)其進(jìn)行角色轉(zhuǎn)換。預(yù)先具備的知識(shí)(rac搭建,單實(shí)例-單實(shí)例dg搭建)
二、實(shí)驗(yàn)環(huán)境介紹
主庫(kù)rac(已安裝rac,并已有數(shù)據(jù)庫(kù)orcl)
rac1:192.168.56.11,sid1:orcl1,version:11.2.0.4 rac2:192.168.56.12,sid2:orcl2,version:11.2.0.4
從庫(kù)(已安裝單實(shí)例數(shù)據(jù)庫(kù)軟件,無(wú)數(shù)據(jù)庫(kù)實(shí)例)
oradg:192.168.56.102,sid:orcldg,version:11.2.0.4
三、搭建dg
** 以下所有主庫(kù)操作都在節(jié)點(diǎn)1上做,如果需要在節(jié)點(diǎn)2上做的,我會(huì)標(biāo)明
1. 主庫(kù)打開(kāi)歸檔模式,并強(qiáng)制寫(xiě)日志
先查看數(shù)據(jù)庫(kù)的歸檔狀態(tài)以及是否開(kāi)啟強(qiáng)制寫(xiě)日志,從下圖可以看到目前數(shù)據(jù)庫(kù)并沒(méi)有打開(kāi)歸檔,也沒(méi)有開(kāi)啟強(qiáng)制寫(xiě)日志
SQL> select log_mode, force_logging from v$database;
數(shù)據(jù)庫(kù)在mount狀態(tài)下打開(kāi)歸檔
SQL> alter system set log_archive_dest_1='location=+data' sid='*' scope=spfile; SQL> shutdown immediate; # 兩節(jié)點(diǎn)都關(guān)閉 SQL> startup mount; # 只開(kāi)啟節(jié)點(diǎn)1 SQL> alter database archivelog; SQL> alter database open;
強(qiáng)制日志寫(xiě),數(shù)據(jù)庫(kù)在open狀態(tài)就能修改
SQL> alter database force logging; SQL> startup; # 當(dāng)節(jié)點(diǎn)1open完畢后,在節(jié)點(diǎn)2上打開(kāi)數(shù)據(jù)庫(kù)
再來(lái)查看數(shù)據(jù)庫(kù)的歸檔狀態(tài)以及是否開(kāi)啟強(qiáng)制寫(xiě)日志
SQL> select log_mode, force_logging from v$database;
2. 主庫(kù)打開(kāi)dataguard開(kāi)關(guān)
SQL> alter system set log_archive_config='dg_config=(orcl,orcldg)' sid='*'; # orcl是主庫(kù)的db_unique_name,orcldg是從庫(kù)的db_unique_name
3. 主庫(kù)設(shè)置遠(yuǎn)程歸檔
SQL> alter system set log_archive_dest_3='service=orcldg valid_for=(online_logfiles,primary_role) db_unique_name=orcldg' sid='*';
4. 將主庫(kù)的口令文件傳送給從庫(kù)
[oracle@rac1 ~]$ scp $ORACLE_HOME/dbs/orapw$ORACLE_SID 192.168.56.102:$ORACLE_HOME/dbs/orapworcldg
5. 從庫(kù)準(zhǔn)備參數(shù)文件
這里參數(shù)文件跟給單實(shí)例搭建單實(shí)例dg沒(méi)什么區(qū)別,所以不做具體介紹
[root@oradg ~]# vi $ORACLE_HOME/dbs/initorcldg.ora *.audit_file_dest='/u01/app/oracle/admin/orcldg/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/oradata/orcldg/controlfile/control01.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='orcl' *.diagnostic_dest='/u01/app/oracle' *.log_archive_config='dg_config=(orcl,orcldg)' *.log_archive_dest_2='location=/u01/app/oracle/oradata/orcldg/archstdlog/ valid_for=(standby_logfiles,standby_role) db_unique_name=orcldg' *.memory_target=838860800 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='exclusive' *.undo_tablespace='UNDOTBS1' standby_file_management=auto # 該參數(shù)默認(rèn)值是manual,需要將其改為auto,表示主庫(kù)的數(shù)據(jù)文件發(fā)生修改(如新建,重命名等),相應(yīng)地從庫(kù)也做相應(yīng)修改 db_unique_name='orcldg' db_file_name_convert='+DATA/orcl/datafile/','/u01/app/oracle/oradata/orcldg/datafile/','+DATA/orcl/tempfile/','/u01/app/oracle/oradata/orcldg/tempfile/' log_file_name_convert='+DATA/orcl/onlinelog/','/u01/app/oracle/oradata/orcldg/onlinelog/'
6. 從庫(kù)中準(zhǔn)備相關(guān)目錄
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/admin/orcldg/adump [oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/controlfile [oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archstdlog [oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/datafile [oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/tempfile [oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/onlinelog
7. 啟動(dòng)從庫(kù)實(shí)例
[oracle@oradg ~]$ export ORACLE_SID=orcldg [oracle@oradg ~]$ sqlplus / as sysdba SQL> create spfile from pfile; SQL> startup nomount
8. 從庫(kù)配置并啟動(dòng)監(jiān)聽(tīng)程序
因?yàn)椴捎胐uplicate方式復(fù)制主庫(kù)數(shù)據(jù),所以需要將從庫(kù)配置為靜態(tài)注冊(cè)的形式
[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/listener.ora SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcldg) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcldg) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521)) ) [oracle@oradg ~]$ lsnrctl start
9. 主庫(kù)配置服務(wù)命名
# 兩個(gè)節(jié)點(diǎn)都要設(shè)置 [oracle@rac1 ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora orcldg = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcldg) ) ) [oracle@rac2 ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora
內(nèi)容跟rac1一致,略
10. 主庫(kù)使用網(wǎng)絡(luò)連接從庫(kù)(測(cè)試連通性)
# 這里我的主庫(kù)的sys密碼是123456,從庫(kù)與主庫(kù)一致 [oracle@rac1 ~]$ sqlplus sys/123456@orcldg as sysdba
11. 在主庫(kù)啟動(dòng)rman復(fù)制從庫(kù)
rman連接主庫(kù)和從庫(kù)
[oracle@rac1 ~]$ rman target / auxiliary sys/123456@orcldg RMAN> duplicate target database for standby from active database;
12. 從庫(kù)添加standbylog
添加的日志大小跟主庫(kù)的onlinelog保持一致,數(shù)量多兩組(主庫(kù)的onlinelog信息查看v$log)
group的編號(hào)不與當(dāng)前的onlinelog重復(fù)即可
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/standbylog/ SQL> alter database add standby logfile group 21 '/u01/app/oracle/oradata/orcldg/standbylog/std01.log' size 50M; SQL> alter database add standby logfile group 22 '/u01/app/oracle/oradata/orcldg/standbylog/std02.log' size 50M; SQL> alter database add standby logfile group 23 '/u01/app/oracle/oradata/orcldg/standbylog/std03.log' size 50M; SQL> alter database add standby logfile group 24 '/u01/app/oracle/oradata/orcldg/standbylog/std04.log' size 50M; SQL> alter database add standby logfile group 25 '/u01/app/oracle/oradata/orcldg/standbylog/std05.log' size 50M; SQL> alter database add standby logfile group 26 '/u01/app/oracle/oradata/orcldg/standbylog/std06.log' size 50M;
13. 從庫(kù)打開(kāi)應(yīng)用日志
SQL> alter database recover managed standby database disconnect from session;
14. 主庫(kù)切換歸檔
SQL> alter system switch logfile;
15. 打開(kāi)從庫(kù)
當(dāng)從庫(kù)應(yīng)用歸檔一段時(shí)間后,就關(guān)閉應(yīng)用歸檔日志,打開(kāi)從庫(kù)。
SQL> alter database recover managed standby database cancel; SQL> alter database open; SQL> alter database recover managed standby database using current logfile disconnect from session;
16. 驗(yàn)證同步
主庫(kù)做修改
SQL> update scott.emp set sal=2000; SQL> commit;
從庫(kù)查詢(xún)
SQL> select * from scott.emp;
至此,給rac搭建一個(gè)單實(shí)例的dg就已經(jīng)做完了,跟單實(shí)例搭建單實(shí)例的dg沒(méi)什么區(qū)別。接下來(lái)介紹如何切換。
四、主從切換準(zhǔn)備
17. 主庫(kù)添加standby logfile歸檔路徑
使用grid賬號(hào),創(chuàng)建歸檔路徑
[grid@rac1 ~]$ asmcmd ASMCMD> lsdg # 查看磁盤(pán)組名字 ASMCMD> cd data ASMCMD> cd orcl ASMCMD> mkdir ARCHSTDLOG
使用sys數(shù)據(jù)庫(kù)賬號(hào),修改數(shù)據(jù)庫(kù)參數(shù)
SQL> alter system set log_archive_dest_2='location=+DATA/ORCL/ARCHSTDLOG/ valid_for=(standby_logfiles,standby_role) db_unique_name=orcl' sid='*';
18. 主庫(kù)添加standby logfile
添加的日志的大小跟主庫(kù)的onlinelog保持一致,數(shù)量多兩組(主庫(kù)的onlinelog信息查看v$log)
SQL> alter database add standby logfile thread 1 group 21 ('+data') size 50M; SQL> alter database add standby logfile thread 1 group 22 ('+data') size 50M; SQL> alter database add standby logfile thread 1 group 23 ('+data') size 50M; SQL> alter database add standby logfile thread 2 group 24 ('+data') size 50M; SQL> alter database add standby logfile thread 2 group 25 ('+data') size 50M; SQL> alter database add standby logfile thread 2 group 26 ('+data') size 50M;
19. 主庫(kù)修改參數(shù)文件
SQL> alter system set standby_file_management=auto sid='*'; SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcldg/datafile/','+DATA/orcl/datafile/','/u01/app/oracle/oradata/orcldg/tempfile/','+DATA/orcl/tempfile/' sid='*' scope=spfile; SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/orcldg/onlinelog/','+DATA/orcl/onlinelog/' sid='*' scope=spfile;
到這里,主庫(kù)轉(zhuǎn)換為備庫(kù)的準(zhǔn)備工作已完成!
20. 從庫(kù)配置tnsnames.ora
這里的配置tnsnames.ora的目的是,當(dāng)原從庫(kù)轉(zhuǎn)變?yōu)樾轮鲙?kù)之后,原主庫(kù)變?yōu)樾聫膸?kù),新主庫(kù)需要給新從庫(kù)發(fā)送歸檔日志,所以這里的tnsnames要指向新從庫(kù),又由于dg庫(kù)應(yīng)用歸檔只能在一個(gè)節(jié)點(diǎn)上, 所以toorcl只指向節(jié)點(diǎn)1。
[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora toorcl = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
21. 從庫(kù)為onlinelog設(shè)置歸檔路徑
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archivelog SQL> alter system set log_archive_dest_1='location=/u01/app/oracle/oradata/orcldg/archivelog/ valid_for=(online_logfiles,primary_role) db_unique_name=orcldg';
22. 從庫(kù)設(shè)置遠(yuǎn)程歸檔參數(shù)
SQL> alter system set log_archive_dest_3='service=toorcl valid_for=(online_logfiles,primary_role) db_unique_name=orcl';
到這里,從庫(kù)轉(zhuǎn)為主庫(kù)的準(zhǔn)備工作已完成!
四、主從切換
23. 查看主庫(kù)的角色轉(zhuǎn)換狀態(tài)
SQL> select database_role,switchover_status from v$database;
24. 在節(jié)點(diǎn)1上主轉(zhuǎn)從
集群在做角色轉(zhuǎn)換時(shí),只能有一個(gè)實(shí)例是打開(kāi)狀態(tài),其余都要關(guān)閉,所以將節(jié)點(diǎn)2的實(shí)例關(guān)閉。
SQL> shutdown immediate; # 只在節(jié)點(diǎn)2上做
在節(jié)點(diǎn)1上執(zhí)行以下命令,將主庫(kù)轉(zhuǎn)為從庫(kù),并且關(guān)閉實(shí)例
SQL> alter database commit to switchover to physical standby with session shutdown;
25. 在節(jié)點(diǎn)3上從轉(zhuǎn)主
SQL> select database_role,switchover_status from v$database;
如果是"NOT ALLOWED"表示歸檔還沒(méi)有應(yīng)用完成,可以等待一段時(shí)間
如果日志全部應(yīng)用了再查看角色轉(zhuǎn)換狀態(tài)
SQL> select database_role,switchover_status from v$database;
如果角色轉(zhuǎn)換狀態(tài)是TO PRIMARY,那么表示可以進(jìn)行角色轉(zhuǎn)換
執(zhí)行從轉(zhuǎn)主的命令,命令執(zhí)行成功后,數(shù)據(jù)庫(kù)的狀態(tài)會(huì)變?yōu)閙ount
SQL> alter database commit to switchover to primary; SQL> alter database open;
26. 打開(kāi)新從庫(kù)
在節(jié)點(diǎn)1和節(jié)點(diǎn)2上
SQL> startup
節(jié)點(diǎn)1上應(yīng)用歸檔
SQL> alter database recover managed standby database using current logfile disconnect from session;
節(jié)點(diǎn)3上切換歸檔
SQL> alter system switch logfile;
27. 驗(yàn)證同步
主庫(kù)做修改
SQL> update scott.emp set sal=3000; SQL> commit;
從庫(kù)查詢(xún)
SQL> select * from scott.emp;
28. 錯(cuò)誤處理
如果發(fā)現(xiàn)日志傳不到備庫(kù)的話(huà)可以在主庫(kù)通過(guò)以下命令查看錯(cuò)誤原因
SQL> select dest_id,dest_name,log_sequence,status,error from v$archive_dest;
如果報(bào)上面的錯(cuò)誤的話(huà),可以把歸檔開(kāi)關(guān)重啟一下即可
SQL> alter system set log_archive_dest_state_3='defer' sid='*'; SQL> alter system set log_archive_dest_state_3='enable' sid='*';
以上是“Oracle如何給rac創(chuàng)建單實(shí)例dg并做主從切換功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(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)容。