您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么搭建Data Guard”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么搭建Data Guard”吧!
一、 規(guī)劃
說明:在Data Guard中,
- db_name:主備庫必須保持一致;
- db_unique_name:主備庫必須不一致;
- service_names和instance_name可以保持一致或不一致。
Data Guard允許主備庫有不同的CPU型號,不同的操作系統(tǒng)(例如windows & linux),不同的操作系統(tǒng)位數(shù)(32-bit/64-bit)或者不同的數(shù)據(jù)庫位數(shù)(32-bit/64-bit)。
Data Guard只支持Oracle database企業(yè)版,不支持標(biāo)準(zhǔn)版本。
在物理備庫中,Oracle主備庫的compatiable參數(shù)必須保持一致(通常情況下,我們說的Data Guard都是指物理備庫)。在邏輯備庫中,備庫的compatiable必須大于或等于主庫參數(shù)。
主庫可以是單實(shí)例庫或者RAC,備庫也可以是單實(shí)例或是RAC。
如果主備庫的操作系統(tǒng)一致,那么主備庫的存儲(chǔ)路徑必須保持不同,否則,備庫可能會(huì)覆蓋主庫文件。
如果主備庫都是RAC,主庫使用了ASM和OMF(Oracle managed files)命名管理,那么備庫也應(yīng)該使用ASM和OMF管理。
step1: 主庫開啟force logging
step2: 備庫配置listener.ora文件
step3: 主備庫配置tnsnames.ora文件
step4: 主庫添加standby logfile
step5: 主備庫修改參數(shù)文件
step6: RMAN復(fù)制數(shù)據(jù)庫
step7: DG檢查,應(yīng)用日志
step8: 開啟備庫,實(shí)時(shí)應(yīng)用日志
# systemctl stop firewalld
# systemctl disable firewalld
# vi /etc/selinux/config
selinux=disabled
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /archivelog/ORCL
Oldest online log sequence 26
Next log sequence to archive 28
Current log sequence 28
# vi /etc/hosts
#Primary IP
172.16.70.178 primary
#Standby IP
172.16.70.179 standby
SQL> alter database force logging;
(Oracle用戶)
備庫添加靜態(tài)監(jiān)聽
$ vi $ORACLE_HOME/network/admin/listener.ora
(添加以下內(nèi)容)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = SBDB)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = SBDB)
)
)
開啟監(jiān)聽
$ lsnrctl start
(主備庫一致)
$ vi $ORACLE_HOME/network/admin/tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)
SBDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = SBDB)
)
)
tns連通性檢測
$ tnsping ORCL
$ tnsping SBDB
SQL> select group#,thread#,bytes/1024/1024 M,status from v$log;
SQL> select member from v$logfile;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo04.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo05.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo06.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ORCL/redo07.log' size 50m;
查看日志組狀態(tài)
SQL> select group#,status,type,member from v$logfile;
(主庫修改參數(shù))
1) 生成參數(shù)文件
SQL> create pfile from spfile;
2) 修改參數(shù)文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initORCL.ora
添加以下內(nèi)容:
db_unique_name=ORCL
log_archive_config='dg_config=(ORCL,SBDB)'
log_archive_dest_1='location=/archivelog/ORCL valid_for=(all_logfiles,all_roles) db_unique_name=ORCL'
log_archive_dest_2='service=SBDB lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=SBDB'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
db_file_name_convert='/u01/app/oracle/oradata/SBDB','/u01/app/oracle/oradata/ORCL'
log_file_name_convert='/u01/app/oracle/oradata/SBDB','/u01/app/oracle/oradata/ORCL'
fal_server=SBDB
fal_client=ORCL
standby_file_management=auto
3) 生成spfile,重啟庫使參數(shù)生效
SQL> shutdown immediate;
SQL> create spfile from pfile;
SQL> startup;
(備庫修改)
1) 將主庫pfile傳到備庫
$ scp initORCL.ora standby:$ORACLE_HOME/dbs/initSBDB.ora
2) 修改參數(shù)文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initSBDB.ora
執(zhí)行以下命令
:%s/ORCL/AAAA/g
:%s/SBDB/ORCL/g
:%s/AAAA/SBDB/g
最后將db_name修改回ORCL
最后結(jié)果如下:
*.audit_file_dest='/u01/app/oracle/admin/SBDB/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/SBDB/control01.ctl','/u01/app/oracle/oradata/SBDB/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='ORCL'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=SBDBXDB)'
*.log_archive_dest_1='LOCATION=/archivelog/SBDB'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=769654784
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
db_unique_name=SBDB
log_archive_config='dg_config=(SBDB,ORCL)'
log_archive_dest_1='location=/archivelog/SBDB valid_for=(all_logfiles,all_roles) db_unique_name=SBDB'
log_archive_dest_2='service=ORCL lgwr async valid_for=(online_logfiles,primary_roles) db_unique_name=ORCL'
log_archive_dest_state_1=enable
log_archive_dest_state_2=enable
db_file_name_convert='/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/SBDB'
log_file_name_convert='/u01/app/oracle/oradata/ORCL','/u01/app/oracle/oradata/SBDB'
fal_server=ORCL
fal_client=SBDB
standby_file_management=auto
3) 備庫創(chuàng)建上述目錄
$ mkdir -p /u01/app/oracle/admin/SBDB/adump
$ mkdir -p /u01/app/oracle/oradata/SBDB
$ mkdir -p /archivelog/SBDB
4) 備庫創(chuàng)建密碼文件
$ cd $ORACLE_HOME/dbs/
$ orapwd file=orapwSBDB password=oracle
1) 備庫開啟到nomount狀態(tài)
SQL> create spfile from pfile;
SQL> startup nomount;
2)RMAN復(fù)制數(shù)據(jù)庫(主庫執(zhí)行)
$ rman target / auxiliary sys/oracle@SBDB
RMAN> duplicate target database for standby from active database;
此時(shí),已經(jīng)完成了Data Guard搭建部分!
1) 查詢主備庫狀態(tài)
(主庫)
SQL> col db_unique_name for a15
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- ------------------ ---------------- --------------------
ORCL READ WRITE PRIMARY FAILED DESTINATION
(備庫)
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
-------------- ------------------ ---------------- --------------------
SBDB MOUNTED PHYSICAL STANDBY SESSIONS ACTIVE
2) 備庫應(yīng)用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
此時(shí)注意檢查備庫SWITCHOVER_STATUS狀態(tài),直到SWITCHOVER_STATUS為NOT ALLOWED為正常。
3) 備庫取消應(yīng)用日志
SQL> alter database recover managed standby database cancel;
4) 開啟備庫
SQL> alter database open;
5) 備庫開啟實(shí)時(shí)應(yīng)用
SQL> alter database recover managed standby database using current logfile disconnect from session;
6) 再次檢查備庫狀態(tài)
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
SBDB READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
7) 查看備庫進(jìn)程狀態(tài)
SQL> select process, pid, status, client_process from v$managed_standby;
PROCESS PID STATUS CLIENT_P
--------- ---------- ------------ --------
ARCH 24183 CONNECTED ARCH
ARCH 24186 CONNECTED ARCH
ARCH 24188 CLOSING ARCH
ARCH 24190 CONNECTED ARCH
RFS 24533 IDLE LGWR
RFS 24527 IDLE UNKNOWN
RFS 24529 IDLE ARCH
RFS 24707 IDLE UNKNOWN
MRP0 24918 APPLYING_LOG N/A
此時(shí),備庫已經(jīng)是實(shí)時(shí)應(yīng)用狀態(tài)(Active Data Guard)
感謝各位的閱讀,以上就是“怎么搭建Data Guard”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么搭建Data Guard這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。