您好,登錄后才能下訂單哦!
這篇文章主要介紹“Oracle Data Guard部署分析”,在日常操作中,相信很多人在Oracle Data Guard部署分析問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Oracle Data Guard部署分析”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
序言
DATAGUARD是通過建立一個PRIMARY和STANDBY組來確立其參照關系。
STANDBY一旦創建,DATAGUARD就會通過將主數據庫(PRIMARY)的REDO傳遞給STANDBY數據庫,然后在STANDBY中應用REDO實現數據庫的同步。
有兩種類型的STANDBY:物理STANDBY和邏輯STANDBY。
物理STANDBY提供與主數據庫完全一樣的拷貝(塊到塊),數據庫SCHEMA,包括索引都是一樣的。它是直接應用REDO實現同步的。邏輯STANDBY則不是這樣,在邏輯STANDBY中,邏輯信息是相同的,但物理組織和數據結構可以不同,它和主庫保持同步的方法是將接收的REDO轉換成SQL語句,然后在STANDBY上執行SQL語句。邏輯STANDBY除災難恢復外還有其它用途,比如用于用戶進行查詢和報表。
安裝環境
在主庫--primary上搭建數據庫軟件,建立監聽,采用dbca搭建實例;
在備庫--standby上搭建數據庫軟件,建立監聽,但是不需要建立實例。
在linux上搭建oracle數據庫,過程略。
步驟概述:
1. 主庫開啟歸檔并設置快速恢復區;
2. 主庫創建歸檔同步目錄;
3. 主庫添加STANDBY日志文件;
4. 主備皆配置網絡---監聽配置文件;
5. 將主庫的密碼文件傳輸到備庫;
6. 修改主庫的參數文件傳輸到備庫,需修改部分信息;
7. 以動態參數文件的形式啟動備庫數據庫;
8. 主庫登錄RMAN,【duplicate】復制數據庫;
[oracle@test1 ~]$ mkdir -p /home/oracle/flash [oracle@test2 ~]$ mkdir -p /home/oracle/flash
SYS@PROD1 > alter system set db_recovery_file_dest='/home/oracle/flash'; alter system set db_recovery_file_dest_size=4G; alter database archivelog;
alter database add standby logfile group 4 '/home/oracle/s1.log' size 50M; alter database add standby logfile group 5 '/home/oracle/s2.log' size 50M; alter database add standby logfile group 6 '/home/oracle/s3.log' size 50M; alter database add standby logfile group 7 '/home/oracle/s4.log' size 50M;
[oracle@test1 ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[oracle@test1 admin]$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = test1.us.oracle.com)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (GLOBAL_DBNAME=PROD1) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (SID_NAME=PROD1)) )
[oracle@test1 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. PROD1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test1.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD1) ) ) PROD1_S = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test2.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = PROD1) ) )
啟動監聽,并測試服務名網絡的通暢。兩臺主機均需測試兩個服務名(此省略主庫的測試):
[oracle@test1 admin]$ lsnrctl start [oracle@test2 admin]$ lsnrctl start
[oracle@test2 admin]$ tnsping prod1 TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 25-FEB-2019 11:46:06 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test1.us.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PROD1))) OK (0 msec) [oracle@test2 admin]$ tnsping prod1_s TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 25-FEB-2019 11:47:04 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = test2.us.oracle.com)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PROD1))) OK (0 msec)
[oracle@test1 dbs]$ cd $ORACLE_HOME/dbs [oracle@test1 dbs]$ ls hc_PROD1.dat init.ora lkPROD1 orapwPROD1 spfilePROD1.ora [oracle@test1 dbs]$ scp orapwPROD1 test2:/u01/app/oracle/product/11.2.0/dbhome_1/dbs oracle@test2's password: orapwPROD1 100% 1536 1.5KB/s 00:00
[oracle@test1 dbs]$ ls hc_PROD1.dat init.ora initPROD1.ora lkPROD1 orapwPROD1 spfilePROD1.ora [oracle@test1 dbs]$ cat initPROD1.ora PROD1.__db_cache_size=260046848 PROD1.__java_pool_size=4194304 PROD1.__large_pool_size=8388608 PROD1.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment PROD1.__pga_aggregate_target=398458880 PROD1.__sga_target=390070272 PROD1.__shared_io_pool_size=0 PROD1.__shared_pool_size=104857600 PROD1.__streams_pool_size=0 *.audit_file_dest='/u01/app/oracle/admin/PROD1/adump' *.audit_trail='db' *.compatible='11.2.0.4.0' *.control_files='/u01/app/oracle/oradata/PROD1/control01.ctl','/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='PROD1' *.db_recovery_file_dest='/home/oracle/flash' *.db_recovery_file_dest_size=4294967296 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=PROD1XDB)' *.memory_target=786432000 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=PROD1 LOG_ARCHIVE_CONFIG='DG_CONFIG=(PROD1,LEILEI)' LOG_ARCHIVE_DEST_1= 'LOCATION=/home/oracle/flash VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=PROD1' LOG_ARCHIVE_DEST_2= 'SERVICE=PROD1_S ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=LEILEI' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc LOG_ARCHIVE_MAX_PROCESSES=30 FAL_SERVER=PROD1 STANDBY_FILE_MANAGEMENT=AUTO
傳輸靜態參數文件到備庫:
[oracle@test1 dbs]$ scp initPROD1.ora test2:/u01/app/oracle/product/11.2.0/dbhome_1/dbs oracle@test2's password: initPROD1.ora 100% 1399 1.4KB/s 00:00
在備庫上修改靜態參數文件:
[oracle@test2 dbs]$ cat initPROD1.ora *.control_files='/u01/app/oracle/oradata/PROD1/control01.ctl','/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl' *.db_block_size=8192 *.db_domain='' *.db_name='PROD1' *.db_recovery_file_dest='/home/oracle/flash' *.db_recovery_file_dest_size=4294967296 *.diagnostic_dest='/u01/app/oracle' *.dispatchers='(PROTOCOL=TCP) (SERVICE=PROD1XDB)' *.memory_target=786432000 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile='EXCLUSIVE' *.undo_tablespace='UNDOTBS1' DB_UNIQUE_NAME=LEILEI LOG_ARCHIVE_CONFIG='DG_CONFIG=(LEILEI,PROD1)' LOG_ARCHIVE_DEST_1= 'LOCATION=/home/oracle/flash VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=LEILEI' LOG_ARCHIVE_DEST_2= 'SERVICE=PROD1 ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PROD1' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=ENABLE REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE LOG_ARCHIVE_FORMAT=%t_%s_%r.arc LOG_ARCHIVE_MAX_PROCESSES=30 FAL_SERVER=PROD1 STANDBY_FILE_MANAGEMENT=AUTO
[oracle@test2 dbs]$ mkdir -p /home/oracle/flash mkdir -p /u01/app/oracle/admin/PROD1/adump mkdir -p /u01/app/oracle/oradata/PROD1 mkdir -p /u01/app/oracle/fast_recovery_area/PROD1
[oracle@test2 ~]$ export ORACLE_SID=PROD1 [oracle@test2 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 25 13:59:23 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SYS@PROD1 >startup nomount; ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes
[oracle@test1 ~]$ rman target sys/oracle@prod1 auxiliary sys/oracle@prod1_s Recovery Manager: Release 11.2.0.4.0 - Production on Mon Feb 25 13:43:23 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: PROD1 (DBID=2222506242) connected to auxiliary database: PROD1 (not mounted) RMAN> duplicate target database for standby from active database nofilenamecheck; Starting Duplicate Db at 2019-02-25 13:43:31 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=10 device type=DISK contents of Memory Script: { backup as copy reuse targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapwPROD1' auxiliary format '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/orapwPROD1' ; } executing Memory Script Starting backup at 2019-02-25 13:43:32 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=17 device type=DISK Finished backup at 2019-02-25 13:43:33 contents of Memory Script: { backup as copy current controlfile for standby auxiliary format '/u01/app/oracle/oradata/PROD1/control01.ctl'; restore clone controlfile to '/u01/app/oracle/fast_recovery_area/PROD1/control02.ctl' from '/u01/app/oracle/oradata/PROD1/control01.ctl'; } executing Memory Script Starting backup at 2019-02-25 13:43:33 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy copying standby control file output file name=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD1.f tag=TAG20190225T134333 RECID=2 STAMP=1001166214 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 Finished backup at 2019-02-25 13:43:36 Starting restore at 2019-02-25 13:43:36 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: copied control file copy Finished restore at 2019-02-25 13:43:37 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 "/u01/app/oracle/oradata/PROD1/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/u01/app/oracle/oradata/PROD1/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/PROD1/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/PROD1/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/PROD1/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/PROD1/example01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oracle/oradata/PROD1/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/PROD1/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/PROD1/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/PROD1/users01.dbf" datafile 5 auxiliary format "/u01/app/oracle/oradata/PROD1/example01.dbf" ; sql 'alter system archive log current'; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oracle/oradata/PROD1/temp01.dbf in control file executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 2019-02-25 13:43:43 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/u01/app/oracle/oradata/PROD1/system01.dbf output file name=/u01/app/oracle/oradata/PROD1/system01.dbf tag=TAG20190225T134343 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf output file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf tag=TAG20190225T134343 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting datafile copy input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf output file name=/u01/app/oracle/oradata/PROD1/example01.dbf tag=TAG20190225T134343 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf output file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf tag=TAG20190225T134343 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/u01/app/oracle/oradata/PROD1/users01.dbf output file name=/u01/app/oracle/oradata/PROD1/users01.dbf tag=TAG20190225T134343 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2019-02-25 13:45:16 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=2 STAMP=1001167339 file name=/u01/app/oracle/oradata/PROD1/system01.dbf datafile 2 switched to datafile copy input datafile copy RECID=3 STAMP=1001167339 file name=/u01/app/oracle/oradata/PROD1/sysaux01.dbf datafile 3 switched to datafile copy input datafile copy RECID=4 STAMP=1001167339 file name=/u01/app/oracle/oradata/PROD1/undotbs01.dbf datafile 4 switched to datafile copy input datafile copy RECID=5 STAMP=1001167339 file name=/u01/app/oracle/oradata/PROD1/users01.dbf datafile 5 switched to datafile copy input datafile copy RECID=6 STAMP=1001167339 file name=/u01/app/oracle/oradata/PROD1/example01.dbf Finished Duplicate Db at 2019-02-25 13:45:32
[oracle@test1 ~]$ export ORACLE_SID=PROD1 [oracle@test1 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 25 13:46:56 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- READ WRITE PRIMARY SESSIONS ACTIVE SYS@PROD1 >select * from v$log; GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIV STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME ---------- ---------- ---------- ---------- ---------- ---------- ------ -------------------------------- ------------- ------------------- ------------ ------------------- 1 1 16 52428800 512 1 NO CURRENT 996478 2019-02-25 14:19:03 2.8147E+14 2 1 14 52428800 512 1 YES INACTIVE 996073 2019-02-25 14:12:33 996161 2019-02-25 14:13:55 3 1 15 52428800 512 1 YES ACTIVE 996161 2019-02-25 14:13:55 996478 2019-02-25 14:19:03
[oracle@test2 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Mon Feb 25 14:04:36 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- MOUNTED PHYSICAL STANDBY RECOVERY NEEDED 備庫處于MOUNTED模式下,只能開啟實時應用在線日志或者歸檔日志。 SYS@PROD1 >select PROCESS,STATUS,SEQUENCE# from v$managed_standby; PROCESS STATUS SEQUENCE# ------------------ ---------------------- ----------------- ARCH CLOSING 15 ARCH CONNECTED 0 ...... ARCH CONNECTED 0 ARCH CONNECTED 0 ARCH CONNECTED 0 RFS IDLE 0 RFS IDLE 0 RFS IDLE 16 33 rows selected. SYS@PROD1 >alter database open; Database altered. SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ------------- ----------------- ------------------- READ ONLY PHYSICAL STANDBY NOT ALLOWED
? 測試1 Test1: SYS@PROD1 >create table t1 (id number); Table created. Test2: SYS@PROD1 >desc t1 ERROR: ORA-04043: object t1 does not exist SYS@PROD1 >recover managed standby database disconnect; Media recovery complete. SYS@PROD1 >desc t1 ERROR: ORA-04043: object t1 does not exist Test1: SYS@PROD1 >alter system switch logfile; System altered. Test2: SYS@PROD1 >desc t1 Name Null? Type ---------------------------------------- ID NUMBER
11G新特性:ADG
Test2: SYS@PROD1 >recover managed standby database cancel; Media recovery complete. SYS@PROD1 >recover managed standby database using current logfile disconnect from session; Media recovery complete. Test1: SYS@PROD1 >create table t2 (id number); Table created. Test2: SYS@PROD1 >desc t2 Name Null? Type ----------------------------------- ID NUMBER
以下為Data Guard最為重要的兩個功能:
參考博客:http://www.cnblogs.com/hllnj2008/p/4995099.html
TEST1: SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- READ WRITE PRIMARY TO STANDBY SYS@PROD1 >alter database commit to switchover to physical standby; Database altered. SYS@PROD1 >conn / as sysdba; Connected to an idle instance. SYS@PROD1 >startup ORACLE instance started. Total System Global Area 1219260416 bytes Fixed Size 2252744 bytes Variable Size 788529208 bytes Database Buffers 419430400 bytes Redo Buffers 9048064 bytes Database mounted. Database opened. SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- READ ONLY PHYSICAL STANDBY TO PRIMARY TEST2: SYS@PROD1 >recover managed standby database cancel; Media recovery complete. SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- READ ONLY PHYSICAL STANDBY TO PRIMARY SYS@PROD1 >alter database commit to switchover to primary; Database altered. SYS@PROD1 >select open_mode,database_role,switchover_status from v$database; OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS ---------------------------------------- -------------------------------- ---------------------------------------- MOUNTED PRIMARY NOT ALLOWED SYS@PROD1 >alter database open; Database altered. SYS@PROD1 >insert into t1 values (1); 1 row created. SYS@PROD1 >commit; Commit complete. SYS@PROD1 >select * from t1; ID ---------- 1 TEST1: SYS@PROD1 >select * from t1; no rows selected SYS@PROD1 >recover managed standby database using current logfile disconnect from session; Media recovery complete. SYS@PROD1 >select * from t1; ID ---------- 1
到此,關于“Oracle Data Guard部署分析”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。