RAC2:關閉庫java
SQL> shutdown Database closed. Database dismounted. ORACLE instance shut down.
RAC1:開啓強制日誌記錄node
SQL> alter database force logging; Database altered.
ALL Node:開啓rac2,並驗證日誌記錄模式sql
RAC1 SQL> select log_mode,force_logging from v$database; LOG_MODE FOR ------------ --- ARCHIVELOG YES RAC2 SQL> startup ORACLE instance started. Total System Global Area 2020970496 bytes Fixed Size 2214776 bytes Variable Size 1224737928 bytes Database Buffers 788529152 bytes Redo Buffers 5488640 bytes Database mounted. Database opened. SQL> select log_mode,force_logging from v$database; LOG_MODE FOR ------------ --- ARCHIVELOG YES
[root@racnode1 u01]# mkdir rmanbak [root@racnode1 u01]# ls app rmanbak [root@racnode1 u01]# chown oracle:oinstall rmanbak
[oracle@racnode1 ~]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Wed Aug 9 10:26:21 2017 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database: ORCL (DBID=1479188731) RMAN> run { allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; allocate channel c4 type disk; backup database format '/u01/rmanbak/FULL_%U.bak'; backup archivelog all format '/u01/rmanbak/ARC_%U.bak'; release channel c1; release channel c2; release channel c3; release channel c4; } using target database control file instead of recovery catalog allocated channel: c1 channel c1: SID=148 instance=orcl1 device type=DISK allocated channel: c2 channel c2: SID=29 instance=orcl1 device type=DISK allocated channel: c3 channel c3: SID=156 instance=orcl1 device type=DISK allocated channel: c4 channel c4: SID=32 instance=orcl1 device type=DISK Starting backup at 09-AUG-2017 10:26:44 channel c1: starting full datafile backup set channel c1: specifying datafile(s) in backup set input datafile file number=00001 name=+DATA/orcl/datafile/system.256.951407925 channel c1: starting piece 1 at 09-AUG-2017 10:26:44 channel c2: starting full datafile backup set channel c2: specifying datafile(s) in backup set input datafile file number=00002 name=+DATA/orcl/datafile/sysaux.257.951407925 input datafile file number=00004 name=+DATA/orcl/datafile/users.259.951407925 channel c2: starting piece 1 at 09-AUG-2017 10:26:44 channel c3: starting full datafile backup set channel c3: specifying datafile(s) in backup set input datafile file number=00003 name=+DATA/orcl/datafile/undotbs1.258.951407925 input datafile file number=00005 name=+DATA/orcl/datafile/undotbs2.264.951408055 channel c3: starting piece 1 at 09-AUG-2017 10:26:45 channel c4: starting full datafile backup set channel c4: specifying datafile(s) in backup set including current control file in backup set channel c4: starting piece 1 at 09-AUG-2017 10:26:52 channel c3: finished piece 1 at 09-AUG-2017 10:26:56 piece handle=/u01/rmanbak/FULL_03sbfaj4_1_1.bak tag=TAG20170809T102644 comment=NONE channel c3: backup set complete, elapsed time: 00:00:11 channel c3: starting full datafile backup set channel c3: specifying datafile(s) in backup set including current SPFILE in backup set channel c3: starting piece 1 at 09-AUG-2017 10:26:57 channel c4: finished piece 1 at 09-AUG-2017 10:26:57 piece handle=/u01/rmanbak/FULL_04sbfaj5_1_1.bak tag=TAG20170809T102644 comment=NONE channel c4: backup set complete, elapsed time: 00:00:05 channel c1: finished piece 1 at 09-AUG-2017 10:26:57 piece handle=/u01/rmanbak/FULL_01sbfaj4_1_1.bak tag=TAG20170809T102644 comment=NONE channel c1: backup set complete, elapsed time: 00:00:13 channel c2: finished piece 1 at 09-AUG-2017 10:26:58 piece handle=/u01/rmanbak/FULL_02sbfaj4_1_1.bak tag=TAG20170809T102644 comment=NONE channel c2: backup set complete, elapsed time: 00:00:14 channel c3: finished piece 1 at 09-AUG-2017 10:26:58 piece handle=/u01/rmanbak/FULL_05sbfajh_1_1.bak tag=TAG20170809T102644 comment=NONE channel c3: backup set complete, elapsed time: 00:00:01 Finished backup at 09-AUG-2017 10:26:58 Starting backup at 09-AUG-2017 10:26:59 current log archived channel c1: starting archived log backup set channel c1: specifying archived log(s) in backup set input archived log thread=1 sequence=5 RECID=1 STAMP=951408120 input archived log thread=2 sequence=1 RECID=2 STAMP=951408150 input archived log thread=1 sequence=6 RECID=5 STAMP=951447623 channel c1: starting piece 1 at 09-AUG-2017 10:26:59 channel c2: starting archived log backup set channel c2: specifying archived log(s) in backup set input archived log thread=2 sequence=2 RECID=3 STAMP=951408156 input archived log thread=2 sequence=3 RECID=4 STAMP=951447623 input archived log thread=2 sequence=4 RECID=8 STAMP=951555111 channel c2: starting piece 1 at 09-AUG-2017 10:26:59 channel c3: starting archived log backup set channel c3: specifying archived log(s) in backup set input archived log thread=1 sequence=7 RECID=6 STAMP=951516208 input archived log thread=1 sequence=8 RECID=7 STAMP=951555108 channel c3: starting piece 1 at 09-AUG-2017 10:26:59 channel c4: starting archived log backup set channel c4: specifying archived log(s) in backup set input archived log thread=1 sequence=9 RECID=11 STAMP=951560819 input archived log thread=2 sequence=5 RECID=9 STAMP=951558975 input archived log thread=2 sequence=6 RECID=10 STAMP=951560429 channel c4: starting piece 1 at 09-AUG-2017 10:26:59 channel c1: finished piece 1 at 09-AUG-2017 10:27:00 piece handle=/u01/rmanbak/ARC_06sbfajj_1_1.bak tag=TAG20170809T102659 comment=NONE channel c1: backup set complete, elapsed time: 00:00:01 channel c2: finished piece 1 at 09-AUG-2017 10:27:00 piece handle=/u01/rmanbak/ARC_07sbfajj_1_1.bak tag=TAG20170809T102659 comment=NONE channel c2: backup set complete, elapsed time: 00:00:01 channel c3: finished piece 1 at 09-AUG-2017 10:27:00 piece handle=/u01/rmanbak/ARC_08sbfajj_1_1.bak tag=TAG20170809T102659 comment=NONE channel c3: backup set complete, elapsed time: 00:00:01 channel c4: finished piece 1 at 09-AUG-2017 10:27:00 piece handle=/u01/rmanbak/ARC_09sbfajj_1_1.bak tag=TAG20170809T102659 comment=NONE channel c4: backup set complete, elapsed time: 00:00:01 Finished backup at 09-AUG-2017 10:27:00 released channel: c1 released channel: c2 released channel: c3 released channel: c4
[oracle@racnode1 ~]$ ll -th /u01/rmanbak/ 總用量 1.3G -rw-r----- 1 oracle asmadmin 89M 8月 9 10:27 ARC_08sbfajj_1_1.bak -rw-r----- 1 oracle asmadmin 81M 8月 9 10:27 ARC_07sbfajj_1_1.bak -rw-r----- 1 oracle asmadmin 4.5M 8月 9 10:26 ARC_09sbfajj_1_1.bak -rw-r----- 1 oracle asmadmin 30M 8月 9 10:26 ARC_06sbfajj_1_1.bak -rw-r----- 1 oracle asmadmin 424M 8月 9 10:26 FULL_02sbfaj4_1_1.bak -rw-r----- 1 oracle asmadmin 96K 8月 9 10:26 FULL_05sbfajh_1_1.bak -rw-r----- 1 oracle asmadmin 588M 8月 9 10:26 FULL_01sbfaj4_1_1.bak -rw-r----- 1 oracle asmadmin 18M 8月 9 10:26 FULL_04sbfaj5_1_1.bak -rw-r----- 1 oracle asmadmin 3.6M 8月 9 10:26 FULL_03sbfaj4_1_1.bak
SQL> alter database create standby controlfile as'/u01/rmanbak/standby.ctl'; Database altered.
SQL> create pfile='/u01/rmanbak/initphyracdb.ora' from spfile; File created.
[oracle@racnode1 dbs]$ pwd /u01/app/oracle/product/11.2.0/db_1/dbs [oracle@racnode1 dbs]$ cp orapworcl1 /u01/rmanbak/
[oracle@racnode1 rmanbak]$ scp * oracle@192.168.30.134:/u01/rmanbak/ The authenticity of host '192.168.30.134 (192.168.30.134)' can't be established. RSA key fingerprint is 43:e6:68:ce:37:01:1f:12:46:19:27:39:a5:ba:02:7d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.30.134' (RSA) to the list of known hosts. oracle@192.168.30.134's password: ARC_06sbfajj_1_1.bak 100% 29MB 29.4MB/s 00:00 ARC_07sbfajj_1_1.bak 100% 81MB 80.8MB/s 00:00 ARC_08sbfajj_1_1.bak 100% 88MB 88.0MB/s 00:01 ARC_09sbfajj_1_1.bak 100% 4598KB 4.5MB/s 00:00 FULL_01sbfaj4_1_1.bak 100% 587MB 117.4MB/s 00:05 FULL_02sbfaj4_1_1.bak 100% 424MB 84.8MB/s 00:05 FULL_03sbfaj4_1_1.bak 100% 3680KB 3.6MB/s 00:00 FULL_04sbfaj5_1_1.bak 100% 18MB 17.7MB/s 00:01 FULL_05sbfajh_1_1.bak 100% 96KB 96.0KB/s 00:00 initphyracdb.ora 100% 1390 1.4KB/s 00:00 orapworcl1 100% 1536 1.5KB/s 00:00 standby.ctl 100% 18MB 17.6MB/s 00:00
orcl.__db_cache_size=771751936 orcl.__java_pool_size=16777216 orcl.__large_pool_size=16777216 orcl.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment orcl.__pga_aggregate_target=822083584 orcl.__sga_target=1207959552 orcl.__shared_io_pool_size=0 orcl.__shared_pool_size=385875968 orcl.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/orcl/adump' *.audit_trail='db' *.cluster_database=false *.compatible='11.2.0.0.0' # 指定控制文件路徑 *.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl' *.db_block_size=8192 *.db_create_file_dest='/u01/app/oracle/oradata/orcl' *.db_domain='' *.db_name='orcl' *.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area' *.db_recovery_file_dest_size=10737418240 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)' orcl.instance_number=1 # 歸檔配置 *.log_archive_config='dg_config=(orcl,rac)' # 本地歸檔 *.log_archive_dest_1='LOCATION=/u01/archive_log VALID_FOR=(ALL_LOGFILES,ALL_ROLES)' # 遠程歸檔 *.log_archive_dest_2='SERVICE=rac LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=rac' *.log_archive_dest_state_1='ENABLE' *.log_archive_dest_state_2='ENABLE' *.log_archive_format='%t_%s_%r.dbf' *.log_archive_max_processes=5 *.memory_target=2030043136 *.open_cursors=300 *.processes=150 # 啓用本地密碼,默認便可 *.remote_login_passwordfile='exclusive' orcl.thread=1 *.service_names='racdg' *.standby_file_management='auto' orcl.undo_tablespace='UNDOTBS1' # dbf文件路徑轉換 *.db_file_name_convert='+DATA/ORCL/DATAFILE','/u01/app/oracle/oradata/orcl' *.db_unique_name='orcl' # 當前節點【對應監聽文件】 *.fal_client='orcl' # 主節點【對應監聽文件】 *.fal_server='rac1','rac2' # 日誌文件路徑轉換 *.log_file_name_convert='+REDO/ORCL','/u01/archive_log','+DATA/orcl','/u01/group_log'
SQL> startup pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initphyracdb.ora' nomount; ORACLE instance started. Total System Global Area 2020970496 bytes Fixed Size 2254664 bytes Variable Size 1224739000 bytes Database Buffers 788529152 bytes Redo Buffers 5447680 bytes
restore controlfile from '/u01/rmanbak/standby.ctl';
SQL> alter database mount; Database altered. SQL> select status from v$instance; STATUS ------------------------------------ MOUNTED
會自動識別當前目錄下的備份文件shell
RMAN> run { allocate channel c1 type disk; allocate channel c2 type disk; allocate channel c3 type disk; allocate channel c4 type disk; restore database ; release channel c1; release channel c2; release channel c3; release channel c4; } released channel: ORA_DISK_1 allocated channel: c1 channel c1: SID=129 device type=DISK allocated channel: c2 channel c2: SID=193 device type=DISK allocated channel: c3 channel c3: SID=7 device type=DISK allocated channel: c4 channel c4: SID=69 device type=DISK Starting restore at 09-AUG-17 Starting implicit crosscheck backup at 09-AUG-17 Crosschecked 9 objects Finished implicit crosscheck backup at 09-AUG-17 Starting implicit crosscheck copy at 09-AUG-17 Finished implicit crosscheck copy at 09-AUG-17 searching for all files in the recovery area cataloging files... no files cataloged channel c1: starting datafile backup set restore channel c1: specifying datafile(s) to restore from backup set channel c1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl//undotbs1.258.951407925 channel c1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl//undotbs2.264.951408055 channel c1: reading from backup piece /u01/rmanbak/FULL_03sbfaj4_1_1.bak channel c2: starting datafile backup set restore channel c2: specifying datafile(s) to restore from backup set channel c2: restoring datafile 00001 to /u01/app/oracle/oradata/orcl//system.256.951407925 channel c2: reading from backup piece /u01/rmanbak/FULL_01sbfaj4_1_1.bak channel c3: starting datafile backup set restore channel c3: specifying datafile(s) to restore from backup set channel c3: restoring datafile 00002 to /u01/app/oracle/oradata/orcl//sysaux.257.951407925 channel c3: restoring datafile 00004 to /u01/app/oracle/oradata/orcl//users.259.951407925 channel c3: reading from backup piece /u01/rmanbak/FULL_02sbfaj4_1_1.bak channel c1: piece handle=/u01/rmanbak/FULL_03sbfaj4_1_1.bak tag=TAG20170809T102644 channel c1: restored backup piece 1 channel c1: restore complete, elapsed time: 00:00:01 channel c3: piece handle=/u01/rmanbak/FULL_02sbfaj4_1_1.bak tag=TAG20170809T102644 channel c3: restored backup piece 1 channel c3: restore complete, elapsed time: 00:00:07 channel c2: piece handle=/u01/rmanbak/FULL_01sbfaj4_1_1.bak tag=TAG20170809T102644 channel c2: restored backup piece 1 channel c2: restore complete, elapsed time: 00:00:15 Finished restore at 09-AUG-17 released channel: c1 released channel: c2 released channel: c3 released channel: c4
SQL> alter database add standby logfile thread 1 group 5 size 50M,group 6 size 50M,group 7 size 50M; Database altered. SQL> alter database add standby logfile thread 2 group 8 size 50M,group 9 size 50M,group 10 size 50M; Database altered.
# 設置本地歸檔路徑 SQL> alter system set log_archive_dest_1='LOCATION=+REDO VALID_FOR=(ALL_LOGFILES,ALL_ROLES)'; System altered. # 設置遠程歸檔路徑 SQL> alter system set log_archive_dest_2='SERVICE=orcl LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'; System altered. # 驗證歸檔設置 SQL> show parameter log_archive # 開啓遠程歸檔傳輸 SQL> alter system set log_archive_dest_state_2=enable; System altered.
SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered.
執行上條命令後,Standby database應爲是延遲傳輸,只有在歸檔時,纔會發生應用,因此在查詢日誌應用狀況時,會發如今當前日誌會顯示IN MEMORY。數據庫
SQL> select thread#, sequence#, applied from v$archived_log; THREAD# SEQUENCE# APPLIED ---------- ---------- --------- 1 132 YES 2 126 YES 1 133 YES 1 134 IN-MEMORY
ADG:11G的新特性,在備庫上已open狀態,打開日誌應用進程,默認會 READ ONLY WITH APPLY狀態模式,在應用日誌的同時也能夠讀standby database進行查詢。11G之間,應用日誌時,只能以mount模式打開。session
Standby Databaseoracle
SQL> alter database recover managed standby database cancel; Database altered.
SQL> alter database open; Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered.
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database; DBID NAME OPEN_MODE CURRENT_SCN PROTECTION_MODE ---------- --------- -------------------- ----------- -------------------- DATABASE_ROLE FOR OPEN_MODE SWITCHOVER_STATUS ---------------- --- -------------------- -------------------- 1479188731 ORCL READ ONLY WITH APPLY 3638179 MAXIMUM PERFORMANCE PHYSICAL STANDBY YES READ ONLY WITH APPLY NOT ALLOWED
Primary Databaseapp
SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination +REDO Oldest online log sequence 21 Next log sequence to archive 22 Current log sequence 22
Standby Databasedom
SQL> archive log list; Database log mode Archive Mode Automatic archival Enabled Archive destination /u01/app/oracle/arch Oldest online log sequence 21 Next log sequence to archive 0 Current log sequence 22
Primary Database性能
SQL> select dbid,name,open_mode,current_scn,protection_mode,database_role,force_logging,open_mode,switchover_status from v$database; DBID NAME OPEN_MODE CURRENT_SCN PROTECTION_MODE ---------- --------- -------------------- ----------- -------------------- DATABASE_ROLE FOR OPEN_MODE SWITCHOVER_STATUS ---------------- --- -------------------- -------------------- 1479188731 ORCL READ WRITE 1407507 MAXIMUM PERFORMANCE PRIMARY YES READ WRITE TO STANDBY
Standby Database
select thread#, sequence#, applied from v$archived_log;
select process from v$managed_standby;