【DG】備庫RMAN還原方式搭建DG(不使用duplicate命令)
一、 本文說明
針對於11g 版本以上的資料庫,在建立備庫時,通常都會在主庫執行以下命令:
RMAN> duplicate target database for standby from active database;
這裡使用的是 from active database 。在這種情況下,複製整個主庫到備庫,會佔用大量業務網路頻寬。尤其是當生產主庫很大的時候,,可能在網路層就會影響業務的進行。並且在這種方式下,需要給備庫新增靜態監聽,避免不了要重啟監聽。如果備庫伺服器上同時跑其他的資料庫,那該庫也會暫停一下業務。
在10g 版本以後,可以透過以下方式進行復制主庫到備庫
第一步:主庫備份‘所有資料庫檔案’
第二步:主庫備份‘備庫控制檔案’
第三步:將上面兩個備份傳輸到備庫主機,並保證放置的目錄與備份的目錄一致。如果條件允許,可以將主庫的備份寫到備份伺服器上,然後將備份掛載到備庫伺服器上即可。
第四步:使用rman 執行以下命令:
RMAN> duplicate target database for standby ;
此時,不會佔用業務網路頻寬,備庫會自動將備份進行還原,以此方式來建立備庫。
本文可以理解為是第二種方式的“衍生版”,主庫不需要執行 RMAN 的 duplicate 命令,以備庫還原的方式來實現物理 DG 的搭建。
二、 規劃
三、 準備工作
1. 關閉 防火牆 (主備庫)
# systemctl stop firewalld
# systemctl disable firewalld
2. 禁用selinux 防火牆 (主備庫)
# vi /etc/selinux/config
selinux= disabled
3. 檢查主庫 歸檔設定
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /archivelog/ORCL
Oldest online log sequence 282
Next log sequence to archive 28 4
Current log sequence 28 4
4. 配置/etc/hosts 檔案(主備庫)
# vi /etc/hosts
# Primary IP
172.16.70.178 primary
#Standby IP
172.16.70.179 standby
四、 搭建DG
1. 開啟強制日誌模式(主庫)
SQL> alter database force logging;
2. 修改tnsname s .ora 檔案(主備庫 )
(主備庫一致)
$ 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 )
)
)
3. 修改 spfile 引數檔案
( 主庫修改 引數 )
1) 生成引數檔案
SQL> create pfile from spfile;
2) 修改引數檔案
$ cd /u01/app/oracle/prod uct/11.2.0/db_1/dbs
$ vi init ORCL .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> st artup ;
(備庫修改 引數 )
1) 將主庫pfile 傳到備庫
$ scp initORCL.ora standby:$ORACLE_HOME/dbs/initSBDB.ora
2) 修改引數檔案
$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
$ vi init SBDB .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
4. 備份主庫
1) 主庫備份資料庫檔案
RMAN> backup database format '/home/oracle/ backup/ backup_orcl_%T_% U .bak';
2) 主庫備份備庫控制檔案
RMAN> backup current controlfile for standby format '/home/oracle/backup/control_std.ctl';
3) 將上面的備份傳輸至備庫相同位置
$ scp /home/oracle/backup/* standby:/home/oracle/backup/
5. 還原備庫
1) 備庫啟動至nomount 狀態
$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup nomount;
2) 備庫還原控制檔案
$ rman target /
RMAN> restore controlfile from '/home/oracle/backup/control_std.ctl';
3) 備庫開啟到mount 狀態
SQL> alter database mount;
4) 執行還原資料庫檔案
RMAN> restore database;
注意不要執行recover database 命令
5) 主備庫建立standby logfile;
(主庫)
SQL> select group#,thread#,bytes/1024/1024 M,status from v$log;
SQL> select member ,type 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 /redo0 5 .log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo0 6 .log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ ORCL /redo0 7 .log' size 50m;
(備庫)
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ SBDB /redo04.log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ SBDB /redo0 5 .log' size 50m;
SQL> alter database add standby logfile '/u01/app/oracle/oradata/ SBDB /redo0 6 .log' size 50m;
SQL> alter database add stan d by logfile '/u01/app/oracle/oradata/ SBDB /redo0 7 .log' size 50m;
6) 備庫執行應用日誌
(此時備庫應處於mount 狀態)
SQL> alter database recover managed standby database using current logfile disconnect from session;
此時alert 日誌如下:
Tue Nov 10 10:56:04 2020
alter database recover managed standby database using current logfile disconnect from session
Attempt to start background Managed Standby Recovery process (SBDB)
Tue Nov 10 10:56:04 2020
MRP0 started with pid=31, OS id=7958
MRP0: Background Managed Standby Recovery process started (SBDB)
started logmerger process
Tue Nov 10 10:56:09 2020
Managed Standby Recovery starting Real Time Apply
Parallel Media Recovery started with 2 slaves
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Additional information: 3
Clearing online redo logfile 1 /u01/app/oracle/oradata/SBDB/redo01.log
Clearing online log 1 of thread 1 sequence number 280
Additional information: 3
Clearing online redo logfile 1 complete
Additional information: 3
Clearing online redo logfile 2 /u01/app/oracle/oradata/SBDB/redo02.log
Clearing online log 2 of thread 1 sequence number 281
Additional information: 3
Completed: alter database recover managed standby database using current logfile disconnect from session
Clearing online redo logfile 2 complete
Additional information: 3
Clearing online redo logfile 3 /u01/app/oracle/oradata/SBDB/redo03.log
Clearing online log 3 of thread 1 sequence number 282
Additional information: 3
Clearing online redo logfile 3 complete
Media Recovery Log /archivelog/SBDB/1_275_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_276_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_277_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_278_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_279_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_280_1047466707.dbf
Media Recovery Log /archivelog/SBDB/1_281_1047466707.dbf
Media Recovery Waiting for thread 1 sequence 282 (in transit)
Recovery of Online Redo Log: Thread 1 Group 4 Seq 282 Reading mem 0
Mem# 0: /u01/app/oracle/oradata/SBDB/redo04.log
7) 備庫取消實時應用
SQL> alter database recover managed standby database cancel;
8 )開啟備庫,開啟實時應用
SQL> alter database open;
SQL> alter database recover managed standby database using current logfile disconnect from session;
此時已經完成DG 搭建
6. 檢查DG 狀態
1 ) 檢查 備 庫狀態
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
2) 檢視主庫狀態
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 TO STANDBY
3 ) 備庫程式狀態
SQL> select process, pid, status, client_process from v$managed_standby;
PROCESS PID STATUS CLIENT_P
--------- ---------- ------------ --------
ARCH 7007 CLOSING ARCH
ARCH 7009 CONNECTED ARCH
ARCH 7011 CLOSING ARCH
ARCH 7013 CLOSING ARCH
RFS 7040 IDLE ARCH
RFS 7031 IDLE UNKNOWN
RFS 7021 IDLE UNKNOWN
RFS 7033 IDLE LGWR
MRP0 8265 APPLYING_LOG N/A
此時,備庫已經是實時應用狀態( Active Data Guard )
---- end ----
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31529886/viewspace-2733291/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【DG】在Linux平臺上搭建單例項的dataguard--rman還原方式Linux單例
- 11g dg 備庫搭建多種方式
- ORACLE DG從庫 Rman備份恢復Oracle
- DG:11.2.0.4 RAC線上duplicate恢復DG
- dg丟失歸檔,使用rman增量備份恢復
- ORACLE DG之備庫角色Oracle
- 【DG】Oracle 19c使用dbca來搭建物理DG--主rac備racOracle
- oracle 19c dg搭建duplicate過程中報錯Oracle
- 【DG】Oracle 19c使用dbca來搭建物理DGOracle
- 物理DG、邏輯DG和快照DG的搭建(視訊講解)
- DG搭建配置方案
- 【DG】在Linux平臺上搭建單例項的dataguard--duplicateLinux單例
- 【DG】Oracle之級聯DG--(cascade dg) --(一主一備一級聯)Oracle
- 【DG】Data Guard主備庫Failove切換AI
- 【DG】Data Guard主備庫Switchover切換
- 在DG備庫備份資料庫並恢復到一個主機上,報錯RMAN-06820資料庫
- DG日常檢查命令
- Oracle RAC+DG搭建Oracle
- 【DG】Data Guard搭建(physical standby)
- DG備庫手動管理 新增資料檔案
- Oracle-DG最大保護模式下,dg備庫出現問題對主庫有什麼影響?Oracle模式
- dg主庫建立檔案備庫未同步解決方法
- Oracle DG異構主備支援Oracle
- Oracle DG備庫手動管理新增資料檔案Oracle
- 11G RAC+DG搭建
- [20190225]測試如何使用dg快速主庫.txt
- 案例:DG主庫未設定force logging導致備庫壞塊
- DG-duplicate操作注意事項(各種報錯應對方法)
- 【邏輯DG滾動升級二】ORACLE11204 邏輯DG滾動升級至12C---DG端前期準備Oracle
- [20221130]最佳化備庫dg遇到的問題2.txt
- ASM REBLANCE引起的DG備庫停止同步問題ORA-16055ASM
- DG備庫未啟動SCN 新特性引起ORA-600 2252
- 用增量備份來快速恢復dg
- 【DG】dg中如何配置多個後臺observerServer
- Oracle 12c 使用RMAN搭建物理備庫(RAC to RAC)Oracle
- Oracle DG管理資料庫屬性Oracle資料庫
- 使用Broker實現DG切換
- ORACLE OCM備考OEM搭建DG報錯:NMO not setuid-root(Unix-only)OracleUI