oracle dataguard配置說明
系統環境
rh linux 6.3
oracle 11g
物理備庫和邏輯備庫
物理備庫:physical standby, 備庫與主數據庫完全一樣的備份(數據為物理塊到塊的復制),數據庫的表和索引都相同,物理結構是相同的。基於RMAN實現,傳輸和直接應用redo log來實現。
邏輯備庫:logical standby ,邏輯備庫,standby側的邏輯信息是一樣的,物理信息和數據結構是不同的,其實現原理是將redo log中的信息提取出SQL,然后在standby執行相應的SQL語句。 (logical standy數據庫是可以OPEN的,也可以用戶數據庫用戶的查詢和報表,但要求數據庫表必須有primary key. —此項待查,實驗進行相應的驗證)
在正式環境做備庫時,我們一般使用物理備庫。
關於Oacrle ADG的授權說明
Oracle Active Data Guard requires a separate license and can only be used with Oracle Database Enterprise Edition. It can be purchased as the Active Data Guard Option for Oracle Database Enterprise Edition. It is also included with Oracle GoldenGate. Basic Data Guard functionality does not require a separate license, and it is included with Oracle Enterprise Edition.
ADG只能用於oracle企業版,但是需要購買額外的license 。 (OGG也是相同的,需要額外購買)
BASIC Data Guard ,也就是基本的DG,是不需要購買額外的license的。 這個是oracle企業版自帶的。
Oracle Data Guard 和 Oracle Active Data Guard
DG::oracle數據庫備庫,數據庫狀態為mount狀態,數據庫信息不可查看。
ADG :oracle active data guard ,oracle備庫處理Open Read-only狀態,數據庫表等信息可查。
DG的三種數據保護模式
最大保護模式: max protection, 數據零丟失,數據雙至多重數據保障。
它要求所有的事務在提交前其redo不僅被寫入到本地的online redo log,還要同時提交到standby數據庫的standby redo log,並確認redo數據至少在一個standby數據庫可用(如果有多個的話),然后才會在primary數據庫上提交。如果出現了什么故障導致standby數據庫不可用的話,primary數據庫會被shutdown。
LGWR SYNC將數據同步傳輸,如遇到網絡故障,如網絡中斷,則主庫會down機。
最大可用模式:max availability,數據零丟失,LGWR SYNC數據同步傳輸。 all redo data has been written to online redo log and at least one of the standy db’s online redo log , the transaction 才提交。
若redo stream不能同時寫入到 synchronized standby db, 則 會按照maxinum performance操作,直到可以同步寫入的時候。
最高性能模式: max performanc模式, 數據最少丟失,因為使用LGWR和ARCH來做數據庫的異步傳輸的應用。 事務可以隨時提交,當前primary庫中的redo數據至少要保證寫入到一個standby數據庫中。
如果網絡條件理想的話,這種模式能夠提供類似最高可用性的數據保護而僅對primary數據庫有輕微的性能影響
一般在應用環境中,用最大可以模式比較多。
配置傳統的DG備庫
主:192.168.5.1 DOG
備:192.168.5.2 DOGSBY
配置主機hosts文件
/etc/hosts
192.168.5.1 oracle01.mytest.com oracle01
192.168.5.2 oracle02.mytest.com oracle02
主備庫配置listener並配置靜態監聽
listener監聽兩邊的數據庫連接,同時在主備切換時,可以順利進行。
此步其實不是必須的,我們把監聽修改為了靜態監聽了。
主:
LISTENER =
|
|
(DESCRIPTION_LIST =
|
|
(DESCRIPTION =
|
|
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle01.mytest.com)(PORT = 1521))
|
|
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
|
|
)
|
|
)
|
|
SID_LIST_LISTENER =
|
|
(SID_LIST =
|
|
(SID_DESC =
|
|
(ORACLE_HOME= /app/oracle/product/11.2.0/dbhome_1)
|
|
(SID_NAME = DOG)
|
|
)
|
|
)
|
備:
LISTENER =
|
|
(DESCRIPTION_LIST =
|
|
(DESCRIPTION =
|
|
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
|
|
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle02.mytest.com)(PORT = 1521))
|
|
)
|
|
)
|
|
SID_LIST_LISTENER =
|
|
(SID_LIST =
|
|
(SID_DESC =
|
|
(ORACLE_HOME= /app/oracle/product/11.2.0/dbhome_1)
|
|
(SID_NAME = DOGSBY)
|
|
)
|
|
)
|
主備庫配置tnsnames
主備:
DOG =
|
|
(DESCRIPTION =
|
|
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle01.mytest.com)(PORT = 1521))
|
|
(CONNECT_DATA =
|
|
(SERVER = DEDICATED)
|
|
(SERVICE_NAME = DOG)
|
|
)
|
|
)
|
|
DOGSBY =
|
|
(DESCRIPTION =
|
|
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.2)(PORT = 1521))
|
|
(CONNECT_DATA =
|
|
(SERVER = DEDICATED)
|
|
(SERVICE_NAME = DOGSBY)
|
|
)
|
|
)
|
|
主庫配置DG所需要的參數信息
規划歸檔:
配置主庫的歸檔日志路徑:
/app/arch/dog
配置備庫的歸檔日志路徑:
/app/arch/dogsby
主庫操作:
alter system set log_archive_config=‘DG_CONFIG=(DOG,DOGSBY)’ scope=both sid=’’;
alter system set log_archive_dest_1=‘LOCATION=/app/arch/dog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DOG’ scope=both sid=’’; #這個配置的
alter system set log_archive_dest_2=‘SERVICE=DOGSBY LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DOGSBY’ scope=both sid=’’; #這里使用的tnsnanes.ora配置來串接兩個數據庫,主與備
alter system set log_archive_dest_state_1=enable;
alter system set log_archive_dest_state_2=enable
alter system set fal_client=‘DOG’ scope=both sid=’’;
alter system set fal_server=‘DOGSBY’ scope=both sid=’’;
alter system set db_file_name_convert=’/app/oracle/oradata/DOGSBY’,’/app/oracle/oradata/DOG’ scope=spfile sid=’’; # 用於主備切換,如果主庫生效,則需要重啟主庫。 在線庫可以不重啟,在下次數據庫重啟時,自動優先加載spfile時,生效。
alter system set log_file_name_convert=’/app/oracle/oradata/DOGSBY’,’/app/oracle/oradata/DOG’ scope=spfile sid=’*’;
alter system set standby_file_management=auto;
主: 創建pfile
create pfile from spfile # 備庫的啟動參數,通過這個pfile來啟動。
修改之后的參數文件 :
主庫:
DOG.__db_cache_size=817889280
|
|
DOG.__java_pool_size=4194304
|
|
DOG.__large_pool_size=12582912
|
|
DOG.__oracle_base=’/app/oracle’#ORACLE_BASE set from environment
|
|
DOG.__pga_aggregate_target=314572800
|
|
DOG.__sga_target=1073741824
|
|
DOG.__shared_io_pool_size=0
|
|
DOG.__shared_pool_size=226492416
|
|
DOG.streams_pool_size=0
|
|
*.audit_file_dest=’/app/oracle/admin/DOG/adump’
|
|
*.audit_trail=‘db’
|
|
*.compatible=‘11.2.0.4.0’
|
|
*.control_files=’/app/oracle/oradata/DOG/control01.ctl’,’/app/oracle/fast_recovery_area/DOG/control02.ctl’
|
|
*.db_block_size=8192
|
|
*.db_domain=’’
|
|
*.db_file_name_convert=’/app/oracle/oradata/DOGSBY’,’/app/oracle/oradata/DOG’
|
|
*.db_name=‘DOG’
|
|
*.db_recovery_file_dest=’/app/oracle/fast_recovery_area’
|
|
*.db_recovery_file_dest_size=43851448320
|
|
*.diagnostic_dest=’/app/oracle’
|
|
*.dispatchers=’(PROTOCOL=TCP) (SERVICE=DOGXDB)’
|
|
*.fal_client=‘DOG’
|
|
*.fal_server=‘DOGSBY’
|
|
*.log_archive_config=‘DG_CONFIG=(DOG,DOGSBY)’
|
|
*.log_archive_dest_1=‘LOCATION=/app/arch/dog/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DOG’
|
|
*.log_archive_dest_2=‘SERVICE=DOGSBY LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DOGSBY’
|
|
*.log_archive_dest_state_1=‘ENABLE’
|
|
*.log_archive_dest_state_2=‘ENABLE’
|
|
*.log_archive_format=’%t%s%r.dbf’
|
|
*.log_file_name_convert=’/app/oracle/oradata/DOGSBY’,’/app/oracle/oradata/DOG’
|
|
*.open_cursors=300
|
|
*.pga_aggregate_target=314572800
|
|
*.processes=500
|
|
*.remote_login_passwordfile=‘EXCLUSIVE’
|
|
*.sessions=555
|
|
*.sga_target=1073741824
|
|
*.standby_file_management=‘AUTO’
|
|
*.undo_tablespace=‘UNDOTBS1’
|
備庫:
*.audit_file_dest=’/app/oracle/admin/DOGSBY/adump’
|
|
*.audit_trail=‘db’
|
|
*.compatible=‘11.2.0.4.0’
|
|
*.control_files=’/app/oracle/oradata/DOGSBY/control01.ctl’,’/app/oracle/fast_recovery_area/DOGSBY/control02.ctl’
|
|
*.db_block_size=8192
|
|
*.db_domain=’’
|
|
*.db_file_name_convert=’/app/oracle/oradata/DOG’,’/app/oracle/oradata/DOGSBY’
|
|
*.db_name=‘DOG’
|
|
*.db_recovery_file_dest=’/app/oracle/fast_recovery_area’
|
|
*.db_recovery_file_dest_size=43851448320
|
|
*.diagnostic_dest=’/app/oracle’
|
|
*.dispatchers=’(PROTOCOL=TCP) (SERVICE=DOGSBYXDB)’
|
|
*.fal_client=‘DOGSBY’
|
|
*.fal_server=‘DOG’
|
|
*.log_archive_config=‘DG_CONFIG=(DOGSBY,DOG)’
|
|
*.log_archive_dest_1=‘LOCATION=/app/arch/dogsby/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DOGSBY’
|
|
*.log_archive_dest_2=‘SERVICE=DOG LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DOG’
|
|
*.log_archive_dest_state_1=‘ENABLE’
|
|
*.log_archive_dest_state_2=‘ENABLE’
|
|
*.log_archive_format=’%t_%s_%r.dbf’
|
|
*.log_file_name_convert=’/app/oracle/oradata/DOG’,’/app/oracle/oradata/DOGSBY’
|
|
*.open_cursors=300
|
|
*.pga_aggregate_target=314572800
|
|
*.processes=500
|
|
*.remote_login_passwordfile=‘EXCLUSIVE’
|
|
*.sessions=555
|
|
*.sga_target=1073741824
|
|
*.standby_file_management=‘AUTO’
|
|
*.undo_tablespace=‘UNDOTBS1’
|
創建standby redo log
主: 用於主備切換時,主切換到備之后的online redo log
ALTER DATABASE ADD STANDBY LOGFILE group 4 (’/app/oracle/oradata/DOG/slog4.log’) SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 5 (’/app/oracle/oradata/DOG/slog5.log’) SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 6 (’/app/oracle/oradata/DOG/slog3.log’) SIZE 50M;
備庫:備升級為主,作用主的standby日志。
在數據庫mount之后,在應用歸檔日志之前創建相應的standby redo log,用於接收主庫傳過來的online redo log
ALTER DATABASE ADD STANDBY LOGFILE group 4 (’/app/oracle/oradata/DOGSBY/slog4.log’) SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 5 (’/app/oracle/oradata/DOGSBY/slog5.log’) SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE group 6 (’/app/oracle/oradata/DOGSBY/slog6.log’) SIZE 50M;
備庫建立相應的目錄
mkdir -p /app/arch/dogsby
mkdir -p /app/oracle/oradata/DOGSBY
mkdir -p /app/oracle/fast_recovery_area/DOGSBY
mkdir -p /app/oracle/admin/DOGSBY/adump
用以存放數據庫相應的目錄
密碼文件
主庫的密碼文件傳輸到備庫
如無密碼文件,則可使用orapwd命令生成 密碼文件
數據庫恢復
主庫備份並將備份傳輸到備庫機器上,使用RMAN進行數據庫恢復。
主庫創建standby controlfile,將此文件傳輸到備份庫,然后進行相應的數據庫恢復
alter database create standby controlfile as ‘/tmp/control01.ctl’
scp到備庫的/tmp目錄
備庫:
將控制文件存放到相應的目錄下:
cp /tmp/control01.ctl /app/oracle/oradata/DOGSBY/control01.ctl
cp /tmp/control01.ctl /app/oracle/fast_recovery_area/DOGSBY/control01.ctl
主:
備份數據庫
RMAN> backup database plus archivelog;
Starting backup at 06-AUG-19
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=266 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=1 STAMP=1015604850
input archived log thread=1 sequence=6 RECID=2 STAMP=1015604853
input archived log thread=1 sequence=7 RECID=3 STAMP=1015605358
input archived log thread=1 sequence=8 RECID=4 STAMP=1015608784
channel ORA_DISK_1: starting piece 1 at 06-AUG-19
channel ORA_DISK_1: finished piece 1 at 06-AUG-19
piece handle=/app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_annnn_TAG20190806T173304_gnllbjyo_.bkp tag=TAG20190806T173304 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-AUG-19
Starting backup at 06-AUG-19
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/app/oracle/oradata/DOG/system01.dbf
input datafile file number=00002 name=/app/oracle/oradata/DOG/sysaux01.dbf
input datafile file number=00003 name=/app/oracle/oradata/DOG/undotbs01.dbf
input datafile file number=00004 name=/app/oracle/oradata/DOG/users01.dbf
channel ORA_DISK_1: starting piece 1 at 06-AUG-19
channel ORA_DISK_1: finished piece 1 at 06-AUG-19
piece handle=/app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_nnndf_TAG20190806T173306_gnllbl65_.bkp tag=TAG20190806T173306 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 06-AUG-19
channel ORA_DISK_1: finished piece 1 at 06-AUG-19
piece handle=/app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_ncsnf_TAG20190806T173306_gnllbt8o_.bkp tag=TAG20190806T173306 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-AUG-19
Starting backup at 06-AUG-19
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=9 RECID=5 STAMP=1015608795
channel ORA_DISK_1: starting piece 1 at 06-AUG-19
channel ORA_DISK_1: finished piece 1 at 06-AUG-19
piece handle=/app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_annnn_TAG20190806T173315_gnllbvdc_.bkp tag=TAG20190806T173315 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 06-AUG-19
將備份傳輸到備庫,對應的目錄下。 以便恢復的時候,不用指定備份片的目錄了
備庫:
mkdir -p /app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/
sqlplus / as sysdba
startup nomount pfile=initDOG.ora
alter database mountstandby database;
restore備庫:
[oracle@oracle02 trace]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Aug 6 18:00:42 2019
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DOG (DBID=4198870852, not open)
RMAN> restore database;
Starting restore at 06-AUG-19
Starting implicit crosscheck backup at 06-AUG-19
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=393 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 06-AUG-19
Starting implicit crosscheck copy at 06-AUG-19
using channel ORA_DISK_1
Crosschecked 2 objects
Finished implicit crosscheck copy at 06-AUG-19
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /app/oracle/oradata/DOGSBY/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /app/oracle/oradata/DOGSBY/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /app/oracle/oradata/DOGSBY/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /app/oracle/oradata/DOGSBY/users01.dbf
channel ORA_DISK_1: reading from backup piece /app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_nnndf_TAG20190806T173306_gnllbl65_.bkp
channel ORA_DISK_1: piece handle=/app/oracle/fast_recovery_area/DOG/backupset/2019_08_06/o1_mf_nnndf_TAG20190806T173306_gnllbl65_.bkp tag=TAG20190806T173306
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 06-AUG-19
在standy備庫端啟動應用歸檔日志:
alter database recover managed standby database disconnect from session;
備庫端的應用日志:
Tue Aug 06 19:28:17 2019
ALTER DATABASE RECOVER managed standby database disconnect from session
Attempt to start background Managed Standby Recovery process (DOGSBY)
Tue Aug 06 19:28:17 2019 開始應用日志了
MRP0 started with pid=24, OS id=24846
MRP0: Background Managed Standby Recovery process started (DOGSBY)
started logmerger process
Tue Aug 06 19:28:22 2019
Managed Standby Recovery not using Real Time Apply
Parallel Media Recovery started with 4 slaves 使用並行者進程
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Media Recovery Log /app/oracle/product/11.2.0/dbhome_1/dbs/arch1_9_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 10
Completed: ALTER DATABASE RECOVER managed standby database disconnect from session
Tue Aug 06 19:32:59 2019
Using STANDBY_ARCHIVE_DEST parameter default value as /app/arch/dogsby/
Tue Aug 06 19:40:01 2019
db_recovery_file_dest_size of 41820 MB is 0.00% used. This is a
user-specified limit on the amount of space that will be used by this
database for recovery-related files, and does not reflect the amount of
space available in the underlying filesystem or ASM diskgroup.
Tue Aug 06 19:42:05 2019
RFS[1]: Assigned to RFS process 25175 RFS進程
RFS[1]: Opened log for thread 1 sequence 12 dbid -96096444 branch 1015599238
Tue Aug 06 19:42:05 2019
RFS[2]: Assigned to RFS process 25177
RFS[2]: Opened log for thread 1 sequence 11 dbid -96096444 branch 1015599238
Archived Log entry 2 added for thread 1 sequence 12 rlc 1015599238 ID 0xfa453f44 dest 2: 新來的日志
Archived Log entry 3 added for thread 1 sequence 11 rlc 1015599238 ID 0xfa453f44 dest 2:
Tue Aug 06 19:42:05 2019
RFS[3]: Assigned to RFS process 25179
RFS[3]: Opened log for thread 1 sequence 10 dbid -96096444 branch 1015599238
Archived Log entry 4 added for thread 1 sequence 10 rlc 1015599238 ID 0xfa453f44 dest 2:
RFS[2]: Selected log 4 for thread 1 sequence 13 dbid -96096444 branch 1015599238
Tue Aug 06 19:42:07 2019
Archived Log entry 5 added for thread 1 sequence 13 ID 0xfa453f44 dest 1:
Tue Aug 06 19:42:07 2019
Primary database is in MAXIMUM PERFORMANCE mode 使用最大性能模式
RFS[4]: Assigned to RFS process 25181
RFS[4]: Selected log 4 for thread 1 sequence 14 dbid -96096444 branch 1015599238
Tue Aug 06 19:42:13 2019
Media Recovery Log /app/arch/dogsby/1_10_1015599238.dbf
Media Recovery Log /app/arch/dogsby/1_11_1015599238.dbf
Media Recovery Log /app/arch/dogsby/1_12_1015599238.dbf
Media Recovery Log /app/arch/dogsby/1_13_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 14 (in transit) 備庫端應用的四個日志文件
Tue Aug 06 19:43:57 2019
RFS[4]: Selected log 5 for thread 1 sequence 15 dbid -96096444 branch 1015599238
Tue Aug 06 19:43:57 2019
Archived Log entry 6 added for thread 1 sequence 14 ID 0xfa453f44 dest 1:
Tue Aug 06 19:43:59 2019
Media Recovery Log /app/arch/dogsby/1_14_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 15 (in transit)
Tue Aug 06 22:00:26 2019
RFS[4]: Selected log 4 for thread 1 sequence 16 dbid -96096444 branch 1015599238
Tue Aug 06 22:00:26 2019
Archived Log entry 7 added for thread 1 sequence 15 ID 0xfa453f44 dest 1:
Tue Aug 06 22:00:28 2019
Media Recovery Log /app/arch/dogsby/1_15_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 16 (in transit)
Tue Aug 06 22:13:59 2019
Warning: VKTM detected a time drift.
Time drifts can result in an unexpected behavior such as time-outs. Please check trace file for more details.
Wed Aug 07 04:00:19 2019
RFS[4]: Selected log 5 for thread 1 sequence 17 dbid -96096444 branch 1015599238
Wed Aug 07 04:00:20 2019
Archived Log entry 8 added for thread 1 sequence 16 ID 0xfa453f44 dest 1:
Wed Aug 07 04:00:21 2019
Media Recovery Log /app/arch/dogsby/1_16_1015599238.dbf 主庫端進行日志切換之后,自動應用新的日志
Media Recovery Waiting for thread 1 sequence 17 (in transit)
standby數據庫查看日志應用情況 :
select thread#,sequence#,archived,applied from v$archived_log order by first_time;
SQL> select thread#,sequence#,archived,applied,t.name,t.dest_id,t.creator,t.standby_dest from v$archived_log t order by first_time;
THREAD# SEQUENCE# ARC APPLIED NAME DEST_ID CREATOR STA
1 9 YES YES /app/oracle/product/11.2.0/dbhome_1/dbs/ 0 ARCH NO
|
|
arch1_9_1015599238.dbf
|
|
1 10 YES YES /app/arch/dogsby/1_10_1015599238.dbf 2 ARCH NO
|
|
1 11 YES YES /app/arch/dogsby/1_11_1015599238.dbf 2 ARCH NO
|
|
1 12 YES YES /app/arch/dogsby/1_12_1015599238.dbf 2 ARCH NO
|
|
1 13 YES YES /app/arch/dogsby/1_13_1015599238.dbf 1 ARCH NO
|
|
1 14 YES YES /app/arch/dogsby/1_14_1015599238.dbf 1 ARCH NO
|
|
1 15 YES YES /app/arch/dogsby/1_15_1015599238.dbf 1 ARCH NO
|
|
1 16 YES YES /app/arch/dogsby/1_16_1015599238.dbf 1 ARCH NO
|
8 rows selected.
primary主庫端查看日志應用情況 :
SQL> select thread#,sequence#,archived,applied,t.name,t.dest_id,t.creator,t.standby_dest from v$archived_log t order by first_time;
THREAD# SEQUENCE# ARC APPLIED NAME DEST_ID CREATOR STA
1 5 YES NO /app/arch/dog/1_5_1015599238.dbf 1 ARCH NO
|
|
1 6 YES NO /app/arch/dog/1_6_1015599238.dbf 1 ARCH NO
|
|
1 7 YES NO /app/arch/dog/1_7_1015599238.dbf 1 ARCH NO
|
|
1 8 YES NO /app/arch/dog/1_8_1015599238.dbf 1 FGRD NO
|
|
1 9 YES NO /app/arch/dog/1_9_1015599238.dbf 1 FGRD NO
|
|
1 10 YES YES DOGSBY 2 ARCH YES
|
|
1 10 YES NO /app/arch/dog/1_10_1015599238.dbf 1 ARCH NO
|
|
1 11 YES NO /app/arch/dog/1_11_1015599238.dbf 1 ARCH NO
|
|
1 11 YES YES DOGSBY 2 ARCH YES
|
|
1 12 YES YES DOGSBY 2 ARCH YES
|
|
1 12 YES NO /app/arch/dog/1_12_1015599238.dbf 1 ARCH NO
|
|
1 13 YES NO /app/arch/dog/1_13_1015599238.dbf 1 ARCH NO
|
|
1 13 YES YES DOGSBY 2 ARCH YES
|
|
1 14 YES NO /app/arch/dog/1_14_1015599238.dbf 1 ARCH NO
|
|
1 14 YES YES DOGSBY 2 LGWR YES
|
|
1 15 YES NO /app/arch/dog/1_15_1015599238.dbf 1 ARCH NO
|
|
1 15 YES YES DOGSBY 2 LGWR YES
|
|
1 16 YES YES DOGSBY 2 LGWR YES
|
|
1 16 YES NO /app/arch/dog/1_16_1015599238.dbf 1 ARCH NO
|
可以看到name為DOGSBY的顯示的為日志應用的情況,其中applied字段為YES,則已應用,這個和備庫端的是對應起來的。
creater為LGWR,則是傳輸的redo日志到standby數據庫端應用。
切換日志后,主備庫日志分析
主:
alter system switch logfile
Wed Aug 07 09:20:45 2019
Thread 1 advanced to log sequence 18 (LGWR switch)
Current log# 3 seq# 18 mem# 0: /app/oracle/oradata/DOG/redo03.log
Wed Aug 07 09:20:45 2019
LNS: Standby redo logfile selected for thread 1 sequence 18 for destination LOG_ARCHIVE_DEST_2 LNS進程查看到 和 LOG_ARCHIVE_DEST_2
Wed Aug 07 09:20:45 2019
Archived Log entry 21 added for thread 1 sequence 17 ID 0xfa453f44 dest 1:
備庫日志
Wed Aug 07 04:00:21 2019
Media Recovery Log /app/arch/dogsby/1_16_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 17 (in transit)
Wed Aug 07 09:20:44 2019
RFS[4]: Selected log 4 for thread 1 sequence 18 dbid -96096444 branch 1015599238 :RFS進程傳輸
Wed Aug 07 09:20:45 2019
Archived Log entry 9 added for thread 1 sequence 17 ID 0xfa453f44 dest 1:
Wed Aug 07 09:20:47 2019
Media Recovery Log /app/arch/dogsby/1_17_1015599238.dbf
Media Recovery Waiting for thread 1 sequence 18 (in transit) 應用日志
查看v$dataguard_status
此視圖保留的dg運行過程狀態
Log Transport Services Control 0 256 0 YES 2019-08-07 09:20:45
ARC1: Beginning to archive thread 1 sequence 17 (1026670-1048932)
Log Transport Services Control 0 257 0 YES 2019-08-07 09:20:45
LNS: Completed archiving log 2 thread 1 sequence 17
Log Transport Services Warning 1 258 0 NO 2019-08-07 09:20:45
LNS: Standby redo logfile selected for thread 1 sequence 18 for destination LOG_ARCHIVE_DEST_2
Log Transport Services Control 0 259 0 YES 2019-08-07 09:20:45
LNS: Beginning to archive log 3 thread 1 sequence 18
Log Transport Services Control 0 260 0 YES 2019-08-07 09:20:45
ARC1: Completed archiving thread 1 sequence 17 (1026670-1048932) 可以看到日志傳輸和歸檔狀態等,及各進程在不同時間點的操作
創建測試數據表驗證
在主庫創建測試表,並在備庫提升至read-only模式驗證
主:
SQL> create table scott.test01 as select * from dba_objects;
Table created.
SQL> select count(*) from scott.test01;
COUNT(*)
|
86259
|
SQL> alter system switch logfile;
System altered.
驗證數據庫已同步之后,再以read only standby方式打開standby數據庫:
備:
alter database recover managed standby database cancel;
shutdown immediate;
startup mount;
alter database open read only;
select count(*) from scott.test01;
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 444597128 bytes
Database Buffers 616562688 bytes
Redo Buffers 5517312 bytes
Database mounted.
SQL> alter database read only;
alter database read only
*
ERROR at line 1:
ORA-02231: missing or invalid option to ALTER DATABASE
SQL> alter database open read only;
Database altered.
SQL> select count(*) from scott.test01;
COUNT(*)
|
86259
|
在這里可以查看到數據已同步。
再次關閉備庫,並恢復DG的應用
shutdown immediate;
startup nomount ; # 此處已創建spfile
alter database mount standby database
alter database recover managed standby database disconnect from session; #啟用歸檔日志的應用。
主庫:
當啟動歸檔應用的時候,則日志應用可再次使用
Wed Aug 07 09:42:57 2019
LNS: Attempting destination LOG_ARCHIVE_DEST_2 network reconnect (3135)
LNS: Destination LOG_ARCHIVE_DEST_2 network reconnect abandoned
Error 3135 for archive log file 2 to 'DOGSBY'
Errors in file /app/oracle/diag/rdbms/dog/DOG/trace/DOG_nsa2_18225.trc:
ORA-03135: connection lost contact
LNS: Failed to archive log 2 thread 1 sequence 20 (3135)
Wed Aug 07 09:43:29 2019
ALTER SYSTEM SET log_archive_dest_state_2='ENABLE' SCOPE=MEMORY SID='*';
Wed Aug 07 09:43:29 2019
Thread 1 advanced to log sequence 21 (LGWR switch)
Current log# 3 seq# 21 mem# 0: /app/oracle/oradata/DOG/redo03.log
Wed Aug 07 09:43:29 2019
Archived Log entry 26 added for thread 1 sequence 20 ID 0xfa453f44 dest 1:
Wed Aug 07 09:43:29 2019
LGWR: Setting 'active' archival for destination LOG_ARCHIVE_DEST_2
ARC3: Standby redo logfile selected for thread 1 sequence 20 for destination LOG_ARCHIVE_DEST_2
LNS: Standby redo logfile selected for thread 1 sequence 21 for destination LOG_ARCHIVE_DEST_2
主備切換
主:查看目錄
select name,database_role,switchover_status from v$database;
當主庫的switchover_status的值為to_standby時,則主備庫才可以切換。
主備切換命令:
主庫操作
alter database commit to switchover to phyical standby
備庫操作:
alter database commit to switchowver to primary;
主庫:
select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PRIMARY SESSIONS ACTIVE
備庫:
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY NOT ALLOWED 不允許狀態
當主庫信息的狀態為:SESSIONS ACTIVE狀態時,則先將physical standby with session shutown,然后切換狀態
alter database commit to switchover to physical standby ; #切換(TO STANDBY狀態時切換)
主:
alter database commit to switchover to physical standby with session shutdown; # 斷開session
執行上述操作后主庫的日志:
Wed Aug 07 10:52:32 2019
alter database commit to switchover to physical standby with session shutdown
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY [Process Id: 23988] (DOG)
Waiting for all non-current ORLs to be archived...
All non-current ORLs have been archived.
Waiting for all FAL entries to be archived...
All FAL entries have been archived.
Waiting for potential Physical Standby switchover target to become synchronized...
Active, synchronized Physical Standby switchover target has been identified
Switchover End-Of-Redo Log thread 1 sequence 21 has been fixed
Switchover: Primary highest seen SCN set to 0x0.0x1068b3
ARCH: Noswitch archival of thread 1, sequence 21
ARCH: End-Of-Redo Branch archival of thread 1 sequence 21
ARCH: LGWR is actively archiving destination LOG_ARCHIVE_DEST_2
ARCH: Standby redo logfile selected for thread 1 sequence 21 for destination LOG_ARCHIVE_DEST_2
Archived Log entry 28 added for thread 1 sequence 21 ID 0xfa453f44 dest 1:
Expanded controlfile section 11 from 28 to 255 records
Requested to grow by 227 records; added 9 blocks of records
ARCH: Archiving is disabled due to current logfile archival
Primary will check for some target standby to have received alls redo
Final check for a synchronized target standby. Check will be made once.
LOG_ARCHIVE_DEST_2 is a potential Physical Standby switchover target
Active, synchronized target has been identified
Target has also received all redo
Backup controlfile written to trace file /app/oracle/diag/rdbms/dog/DOG/trace/DOG_ora_23988.trc
Clearing standby activation ID 4198842180 (0xfa453f44)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause.
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
Archivelog for thread 1 sequence 21 required for standby recovery
Switchover: Primary controlfile converted to standby controlfile succesfully. #控制文件要的到standby數據庫的控制文件了
Switchover: Complete - Database shutdown required
USER (ospid: 23988): terminating the instance
Instance terminated by USER, pid = 23988
Completed: alter database commit to switchover to physical standby with session shutdown #直接關閉數據庫了
Shutting down instance (abort)
License high water mark = 6
Wed Aug 07 10:52:36 2019
Instance shutdown complete
而此時查看備庫的日志為:
Wed Aug 07 10:52:34 2019
RFS[3]: Assigned to RFS process 12302
RFS[3]: Selected log 5 for thread 1 sequence 21 dbid -96096444 branch 1015599238
Wed Aug 07 10:52:34 2019
Archived Log entry 13 added for thread 1 sequence 21 ID 0xfa453f44 dest 1:
Wed Aug 07 10:52:34 2019
RFS[4]: Assigned to RFS process 12300
RFS[4]: Possible network disconnect with primary database
Wed Aug 07 10:52:34 2019
RFS[1]: Possible network disconnect with primary database 斷開與原主庫的連接
Wed Aug 07 10:52:35 2019
Media Recovery Log /app/arch/dogsby/1_21_1015599238.dbf 應用了一個日志
Identified End-Of-Redo (switchover) for thread 1 sequence 21 at SCN 0x0.1068b3
Resetting standby activation ID 4198842180 (0xfa453f44) 重置了這個操作
Media Recovery End-Of-Redo indicator encountered
Media Recovery Continuing
Media Recovery Waiting for thread 1 sequence 22 應用了日志
此時再查看備庫的狀態:
而此時standby備庫的狀態由原來的NOT ALLOWED狀態,已經到的TO_PRIMARY狀態了
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY NOT ALLOWED
SQL>
SQL>
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY TO PRIMARY 主庫執行切換后,備庫收到信息后,則此狀態變了。
那么將備庫提升為主庫:
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY TO PRIMARY
SQL> alter database commit to switchover to primary;
Database altered.
SQL> select name,open_mode from v$database;
NAME OPEN_MODE
DOG MOUNTED
SQL> alter database open;
Database altered.
SQL>
SQL>
SQL> select name,database_role,switchover_status from v$database;
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PRIMARY FAILED DESTINATION # 因為原為切換之后,並沒有啟動
備庫提升為主庫后,備庫的alter日志:
Identified End-Of-Redo (switchover) for thread 1 sequence 21 at SCN 0x0.1068b3
Resetting standby activation ID 4198842180 (0xfa453f44)
Media Recovery End-Of-Redo indicator encountered
Media Recovery Continuing
Media Recovery Waiting for thread 1 sequence 22
Wed Aug 07 11:01:15 2019
alter database commit to switchover to primary
ALTER DATABASE SWITCHOVER TO PRIMARY (DOGSBY) 提升為主庫
Maximum wait for role transition is 15 minutes.
Switchover: Media recovery is still active
Role Change: Canceling MRP - no more redo to apply
Wed Aug 07 11:01:16 2019
MRP0: Background Media Recovery cancelled with status 16037
Errors in file /app/oracle/diag/rdbms/dogsby/DOGSBY/trace/DOGSBY_pr00_10873.trc:
ORA-16037: user requested cancel of managed recovery operation
Recovery interrupted!
Wed Aug 07 11:01:17 2019
MRP0: Background Media Recovery process shutdown (DOGSBY)
Role Change: Canceled MRP
Backup controlfile written to trace file /app/oracle/diag/rdbms/dogsby/DOGSBY/trace/DOGSBY_ora_10834.trc
SwitchOver after complete recovery through change 1075379
Online log /app/oracle/oradata/DOGSBY/redo01.log: Thread 1 Group 1 was previously cleared 當前redo log使用情況
Online log /app/oracle/oradata/DOGSBY/redo02.log: Thread 1 Group 2 was previously cleared
Online log /app/oracle/oradata/DOGSBY/redo03.log: Thread 1 Group 3 was previously cleared
Standby became primary SCN: 1075377
Switchover: Complete - Database mounted as primary
Completed: alter database commit to switchover to primary
Wed Aug 07 11:01:28 2019
ARC1: Becoming the 'no SRL' ARCH
Wed Aug 07 11:01:52 2019
alter database open 打開數據庫操作
Wed Aug 07 11:01:52 2019
Assigning activation ID 4198914298 (0xfa4658fa)
Thread 1 advanced to log sequence 23 (thread open)
Thread 1 opened at log sequence 23
Current log# 2 seq# 23 mem# 0: /app/oracle/oradata/DOGSBY/redo02.log 當前current log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Wed Aug 07 11:01:52 2019
SMON: enabling cache recovery
Wed Aug 07 11:01:52 2019
Archived Log entry 14 added for thread 1 sequence 22 ID 0xfa4658fa dest 1:
Wed Aug 07 11:01:52 2019
NSA2 started with pid=24, OS id=12523
Wed Aug 07 11:01:52 2019
Error 1034 received logging on to the standby
PING[ARC2]: Heartbeat failed to connect to standby 'DOG'. Error is 1034. 因為原來的主庫切換后shutdown abort了,所以現在還連接不上
[10834] Successfully onlined Undo Tablespace 2.
Undo initialization finished serial:0 start:2397233832 end:2397233892 diff:60 (0 seconds)
Dictionary check beginning
Dictionary check complete
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is ZHS16GBK
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Wed Aug 07 11:01:53 2019
QMNC started with pid=25, OS id=12525
LOGSTDBY: Validating controlfile with logical metadata
LOGSTDBY: Validation complete
Completed: alter database open
Wed Aug 07 11:01:53 2019
Starting background process CJQ0
Wed Aug 07 11:01:53 2019
CJQ0 started with pid=28, OS id=12541
Error 1034 received logging on to the standby
FAL[server, ARC2]: Error 1034 creating remote archivelog file 'DOG'
FAL[server, ARC2]: FAL archive failed, see trace file.
ARCH: FAL archive failed. Archiver continuing
ORACLE Instance DOGSBY - Archival Error. Archiver continuing.
Thread 1 advanced to log sequence 24 (LGWR switch)
Current log# 3 seq# 24 mem# 0: /app/oracle/oradata/DOGSBY/redo03.log
Wed Aug 07 11:01:55 2019
ARC3: STARTING ARCH PROCESSES
Wed Aug 07 11:01:55 2019
ARC4 started with pid=26, OS id=12544
ARC4: Archival started
ARC3: STARTING ARCH PROCESSES COMPLETE
Archived Log entry 15 added for thread 1 sequence 23 ID 0xfa4658fa dest 1:
Shutting down archive processes
ARCH shutting down
ARC4: Archival stopped
原主庫操作:
因為原主庫切換為當前備庫了。
所以啟動新備庫:
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1068937216 bytes
Fixed Size 2260088 bytes
Variable Size 444597128 bytes
Database Buffers 616562688 bytes
Redo Buffers 5517312 bytes
SQL> alter database mount standby database;
Database altered.
SQL> select name,database_role,switchover_status from v$database; 查看狀態,新備庫需要應用日志
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY RECOVERY NEEDED
SQL> alter database recover managed standby database disconnect from session; 啟動應用日志
Database altered.
SQL> select name,database_role,switchover_status from v$database; 狀態正常
NAME DATABASE_ROLE SWITCHOVER_STATUS
DOG PHYSICAL STANDBY NOT ALLOWED
SQL> select thread#,sequence#,archived,applied,t.name,t.dest_id,t.creator,t.standby_dest from v$archived_log t order by first_time;
查看日志的應用狀態,當同步應用時,則此就是一次完整的數據主備切換。
常用管理命令
standby查看備庫管理進程
SQL> select process,client_process,sequence#,status from v$managed_standby;
PROCESS CLIENT_P SEQUENCE# STATUS
ARCH ARCH 15 CLOSING
ARCH ARCH 0 CONNECTED
ARCH ARCH 16 CLOSING
ARCH ARCH 14 CLOSING 四個歸檔
MRP0 N/A 17 WAIT_FOR_LOG
RFS ARCH 0 IDLE
RFS UNKNOWN 0 IDLE
RFS UNKNOWN 0 IDLE
RFS LGWR 17 IDLE 四個RFS進程,這個和alert日志中的信息對應
查看主庫的管理進程
select pid,process,status,sequence# from v$managed_standby;
SQL> select pid,process,status,sequence# from v$managed_standby;
PID PROCESS STATUS SEQUENCE#
|
10242 ARCH CLOSING 16
|
|
10244 ARCH CLOSING 14
|
|
10246 ARCH CLOSING 12
|
|
10248 ARCH CLOSING 15
|
|
18225 LNS WRITING 17 # LNS進程
|
主備狀態檢查 :
select DATABASE_ROLE from vdatabase;selectOPENMODE,PROTECTIONMODE,PROTECTIONLEVEL,SWITCHOVERSTATUSfromv
database;selectOPENMODE,PROTECTIONMODE,PROTECTIONLEVEL,SWITCHOVERSTATUSfromvdatabase;
SELECT COUNT(*) FROM V$SESSION WHERE USERNAME IS NOT NULL;
備庫狀態檢查:
select DATABASE_ROLE from vdatabase;selectOPENMODE,PROTECTIONMODE,PROTECTIONLEVEL,SWITCHOVERSTATUSfromv
database;selectOPENMODE,PROTECTIONMODE,PROTECTIONLEVEL,SWITCHOVERSTATUSfromvdatabase;
select open_mode, protection_mode, protection_level, switchover_status from v$database;
在備庫端啟用和停用數據日志應用
管理日志應用服務
在standby端將數據庫啟動到read open狀態
alter database open read only;
在standby端啟動Standby redo日志
alter database recover managed standby database disconnect from session;
停止Standby redo日志應用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
再次啟動Standby redo日志
alter database recover managed standby database disconnect from session;
主備切換:
主至備:
alter database commit to switchover to physical standby ; (TO STANDBY狀態時)
alter database commit to switchover to physical standby disconnect from shutdown; (v$database swithover_status為SESSION ACTIVE狀態時,切換后數據庫為shudown abort)
startup nomout; (新備庫啟動步驟)
alter database mount standby database ;
alter database recover managed standby database disconnect from session;
alter database reover managed standby database cancel;
備至主:
alter database commit to switchover to primary; (TO PRIMARY狀態時)
alter database commit to switchover to primary disconnect from shutdown ; (v$database swithover_status為SESSION ACTIVE狀態時)
alter database open; 新主庫啟動至open
查看數據庫狀態
select name,open_mode,database_role,switchover_status from v$database;
修改保護模式:(默認為MAXIMUM PERFORMANCE模式)
alter database set standby database to maximize availability;
查看日志:
select group#, bytes/1024/1024 from v$log;--查看原有日志
select group#, bytes/1024/1024 from v$standby_log;--查看standby日志
1
|
|
2
|
引申思考
上述步驟便是傳統的DG搭建模式,standby端為mount的狀態,如果需要臨時查看standby數據庫中的數據,則需要將standby數據庫提升至read only模式。應用完畢之后,再次到mount狀態應用。
搭建過程中遇到的問題:
在初始化參數的設定時,設置歸檔路徑時應用的是ENABLE大寫的,而oracle在這個過程中不認大寫,這是個錯誤操作,需要使用小寫的enable參數設定。修改如下:
在初始化參數中指定 initTSTSBY.ora中
alter system set log_archive_dest_state_1=enable
alter system set log_archive_dest_state_2=enable
ADG的搭建過程:
基本配置步驟是相同的,區別在於ADG備庫是直接read-only的狀態
當上述DG的過程,直接提升為ADG
備庫端操作:
alter database recover managed standby database cancel; 停止日志應用
alter database open read only;
alter database recover managed standby database disconnect from session;
主:
alter system switch logfile ;后續觀察可以看日志的應用
在使用RMAN配置備庫的時候,可以使用duplicate命令來直接實現ADG的搭建
rman target sys/oracle@DOG auxiliary sys/oracle@DOGSBY
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate auxiliary channel stby1 type disk;
allocate auxiliary channel stby2 type disk;
duplicate target database for standby from active database nofilenamecheck;
release channel c1;
release channel c2;
release channel stby1;
release channel stby2;
}
執行過程中的日志信息。有興趣的話,可以分析具體的步驟:
oracle@oracle01 ~]$ rman target sys/oracle@DOG auxiliary sys/oracle@DOGSBY
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Apr 7 14:31:59 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: DOG (DBID=4059664894)
connected to auxiliary database: DOG (not mounted)
RMAN>
RMAN>
RMAN>
RMAN> run {
2> allocate channel c1 type disk;
allocate channel c2 type disk;
3> 4> allocate auxiliary channel stby1 type disk;
5> allocate auxiliary channel stby2 type disk;
6> duplicate target database for standby from active database nofilenamecheck;
7> release channel c1;
8> release channel c2;
9> release channel stby1;
10> release channel stby2;
11> }
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: SID=45 device type=DISK
allocated channel: c2
channel c2: SID=1 device type=DISK
allocated channel: stby1
channel stby1: SID=20 device type=DISK
allocated channel: stby2
channel stby2: SID=21 device type=DISK
Starting Duplicate Db at 2015-04-07 14:35:17
contents of Memory Script:
{
backup as copy reuse
targetfile '/app/oracle/product/11.2.0/dbhome_1/dbs/orapwDOG' auxiliary format
'/app/oracle/product/11.2.0/dbhome_1/dbs/orapwDOGSBY' ;
}
executing Memory Script
Starting backup at 2015-04-07 14:35:17
Finished backup at 2015-04-07 14:35:19
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/app/oracle/oradata/DOGSBY/control01.ctl';
restore clone controlfile to '/app/oracle/oradata/DOGSBY/control02.ctl' from
'/app/oracle/oradata/DOGSBY/control01.ctl';
}
executing Memory Script
Starting backup at 2015-04-07 14:35:19
channel c1: starting datafile copy
copying standby control file
output file name=/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_DOG.f tag=TAG20150407T143519 RECID=1 STAMP=876407719
channel c1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-04-07 14:35:20
Starting restore at 2015-04-07 14:35:20
channel stby2: skipped, AUTOBACKUP already found
channel stby1: copied control file copy
Finished restore at 2015-04-07 14:35:28
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
set newname for tempfile 1 to
"/app/oracle/oradata/DOGSBY/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/app/oracle/oradata/DOGSBY/system01.dbf";
set newname for datafile 2 to
"/app/oracle/oradata/DOGSBY/sysaux01.dbf";
set newname for datafile 3 to
"/app/oracle/oradata/DOGSBY/undotbs01.dbf";
set newname for datafile 4 to
"/app/oracle/oradata/DOGSBY/users01.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/app/oracle/oradata/DOGSBY/system01.dbf" datafile
2 auxiliary format
"/app/oracle/oradata/DOGSBY/sysaux01.dbf" datafile
3 auxiliary format
"/app/oracle/oradata/DOGSBY/undotbs01.dbf" datafile
4 auxiliary format
"/app/oracle/oradata/DOGSBY/users01.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /app/oracle/oradata/DOGSBY/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 2015-04-07 14:35:33
channel c1: starting datafile copy
input datafile file number=00001 name=/app/oracle/oradata/DOG/system01.dbf
channel c2: starting datafile copy
input datafile file number=00002 name=/app/oracle/oradata/DOG/sysaux01.dbf
output file name=/app/oracle/oradata/DOGSBY/system01.dbf tag=TAG20150407T143533
channel c1: datafile copy complete, elapsed time: 00:00:15
channel c1: starting datafile copy
input datafile file number=00003 name=/app/oracle/oradata/DOG/undotbs01.dbf
output file name=/app/oracle/oradata/DOGSBY/sysaux01.dbf tag=TAG20150407T143533
channel c2: datafile copy complete, elapsed time: 00:00:15
channel c2: starting datafile copy
input datafile file number=00004 name=/app/oracle/oradata/DOG/users01.dbf
output file name=/app/oracle/oradata/DOGSBY/undotbs01.dbf tag=TAG20150407T143533
channel c1: datafile copy complete, elapsed time: 00:00:01
output file name=/app/oracle/oradata/DOGSBY/users01.dbf tag=TAG20150407T143533
channel c2: datafile copy complete, elapsed time: 00:00:01
Finished backup at 2015-04-07 14:35:50
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=876407868 file name=/app/oracle/oradata/DOGSBY/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=876407868 file name=/app/oracle/oradata/DOGSBY/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=876407868 file name=/app/oracle/oradata/DOGSBY/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=876407868 file name=/app/oracle/oradata/DOGSBY/users01.dbf
Finished Duplicate Db at 2015-04-07 14:35:52
released channel: c1
released channel: c2
released channel: stby1
released channel: stby2
Oracle RAC到單機的備庫搭建
基本步驟是相同的,不同點在於oracle rac有兩至多個實例,所以在設置歸檔日志轉換路徑時需要增加sid=““選項
Oracle RAC 環境使用ASM管理時,可以有類似的配置
alter system set log_archive_dest_2=‘service=DOG2 db_unique_name=DOG’ sid=’’;
alter system set standby_archive_dest=’ +RECVG/DOG/arch_dog’ sid=’’; # 如果不指定,則需要單獨指定
DOG2.__db_cache_size=45365592064
DOG1.__db_cache_size=44962938880
DOG1.__java_pool_size=939524096
DOG2.__java_pool_size=939524096
DOG1.__large_pool_size=805306368
DOG2.__large_pool_size=805306368
DOG2.__oracle_base='/app/oracle'#ORACLE_BASE set from environment
DOG1.__oracle_base='/app/oracle'#ORACLE_BASE set from environment
DOG1.__pga_aggregate_target=20669530112
DOG2.__pga_aggregate_target=20669530112
DOG1.__sga_target=61874372608
DOG2.__sga_target=61874372608
DOG1.__shared_io_pool_size=536870912
DOG2.__shared_io_pool_size=0
DOG2.__shared_pool_size=14361296896
DOG1.__shared_pool_size=13958643712
DOG1.__streams_pool_size=268435456
DOG2.streams_pool_size=0
*.audit_file_dest='/app/oracle/admin/DOG/adump'
*.audit_trail='db'
*.cluster_database=true
*.compatible='11.2.0.4.0'
*.control_files='+DATAVG/dog/controlfile/current.315.898601063','+DATAVG/dog/controlfile/current.316.898601063'
*.db_block_size=8192
*.db_create_file_dest='+DATAVG'
*.db_domain=''
*.db_name='DOG'
*.db_recovery_file_dest='+DATAVG'
*.db_recovery_file_dest_size=42949672960
*.diagnostic_dest='/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DOGXDB)'
DOG2.instance_number=2
DOG1.instance_number=1
*.log_archive_dest_1='location=+RECVG'
*.log_archive_format='%t%s%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=20615004160
*.processes=1500
*.remote_listener='rg77003-cluster-scan:1521'
*.remote_login_passwordfile='exclusive'
*.sessions=1655
*.sga_target=61847109632
DOG2.thread=2
DOG1.thread=1
*.undo_retention=86400
DOG2.undo_tablespace='UNDOTBS2'
DOG1.undo_tablespace='UNDOTBS1'
alter system set log_archive_dest_2='service=DOG2 db_unique_name=DOG' sid='DOG1';
alter system set log_archive_dest_2='service=DOG1 db_unique_name=DOG' sid='DOG2';
alter system set standby_archive_dest=' +RECVG/DOG/arch_dog' sid='DOG1';
alter system set standby_archive_dest=' +RECVG/DOG/arch_dog' sid='DOG2';
alter system set log_archive_config='dg_config=(DOG,DOGSBY)';
alter system set log_archive_dest_3='service=DOGSBY lgwr async VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=DOGSBY' sid='DOG1';
alter system set log_archive_dest_3='service=DOGSBY lgwr async VALID_FOR=(ALL_LOGFILES,ALL_ROLES) db_unique_name=DOGSBY' sid='DOG2';
alter system set standby_file_management=auto;
alter system set fal_server='DOGSBY';
alter system set fal_client='DOG1' sid='DOG1';
alter system set fal_client='YZBL2' sid='DOG2';
————————————————
版權聲明:本文為CSDN博主「Martin201609」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/Martin201609/java/article/details/98618240