您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么搭建Data Guard”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么搭建Data Guard”吧!
一、 規劃
說明:在Data Guard中,
- db_name:主備庫必須保持一致;
- db_unique_name:主備庫必須不一致;
- service_names和instance_name可以保持一致或不一致。
Data Guard允許主備庫有不同的CPU型號,不同的操作系統(例如windows & linux),不同的操作系統位數(32-bit/64-bit)或者不同的數據庫位數(32-bit/64-bit)。
Data Guard只支持Oracle database企業版,不支持標準版本。
在物理備庫中,Oracle主備庫的compatiable參數必須保持一致(通常情況下,我們說的Data Guard都是指物理備庫)。在邏輯備庫中,備庫的compatiable必須大于或等于主庫參數。
主庫可以是單實例庫或者RAC,備庫也可以是單實例或是RAC。
如果主備庫的操作系統一致,那么主備庫的存儲路徑必須保持不同,否則,備庫可能會覆蓋主庫文件。
如果主備庫都是RAC,主庫使用了ASM和OMF(Oracle managed files)命名管理,那么備庫也應該使用ASM和OMF管理。
step1: 主庫開啟force logging
step2: 備庫配置listener.ora文件
step3: 主備庫配置tnsnames.ora文件
step4: 主庫添加standby logfile
step5: 主備庫修改參數文件
step6: RMAN復制數據庫
step7: DG檢查,應用日志
step8: 開啟備庫,實時應用日志
# 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用戶)
備庫添加靜態監聽
$ vi $ORACLE_HOME/network/admin/listener.ora
(添加以下內容)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = SBDB)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = SBDB)
)
)
開啟監聽
$ 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;
查看日志組狀態
SQL> select group#,status,type,member from v$logfile;
(主庫修改參數)
1) 生成參數文件
SQL> create pfile from spfile;
2) 修改參數文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initORCL.ora
添加以下內容:
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,重啟庫使參數生效
SQL> shutdown immediate;
SQL> create spfile from pfile;
SQL> startup;
(備庫修改)
1) 將主庫pfile傳到備庫
$ scp initORCL.ora standby:$ORACLE_HOME/dbs/initSBDB.ora
2) 修改參數文件
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi initSBDB.ora
執行以下命令
:%s/ORCL/AAAA/g
:%s/SBDB/ORCL/g
:%s/AAAA/SBDB/g
最后將db_name修改回ORCL
最后結果如下:
*.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) 備庫創建上述目錄
$ mkdir -p /u01/app/oracle/admin/SBDB/adump
$ mkdir -p /u01/app/oracle/oradata/SBDB
$ mkdir -p /archivelog/SBDB
4) 備庫創建密碼文件
$ cd $ORACLE_HOME/dbs/
$ orapwd file=orapwSBDB password=oracle
1) 備庫開啟到nomount狀態
SQL> create spfile from pfile;
SQL> startup nomount;
2)RMAN復制數據庫(主庫執行)
$ rman target / auxiliary sys/oracle@SBDB
RMAN> duplicate target database for standby from active database;
此時,已經完成了Data Guard搭建部分!
1) 查詢主備庫狀態
(主庫)
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) 備庫應用日志
SQL> alter database recover managed standby database using current logfile disconnect from session;
此時注意檢查備庫SWITCHOVER_STATUS狀態,直到SWITCHOVER_STATUS為NOT ALLOWED為正常。
3) 備庫取消應用日志
SQL> alter database recover managed standby database cancel;
4) 開啟備庫
SQL> alter database open;
5) 備庫開啟實時應用
SQL> alter database recover managed standby database using current logfile disconnect from session;
6) 再次檢查備庫狀態
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) 查看備庫進程狀態
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
此時,備庫已經是實時應用狀態(Active Data Guard)
感謝各位的閱讀,以上就是“怎么搭建Data Guard”的內容了,經過本文的學習后,相信大家對怎么搭建Data Guard這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。