您好,登錄后才能下訂單哦!
上一篇文章介紹了Data Guard 12cR2中3個特性,本篇文章將繼續介紹部分新特性。
| Using DBCA to Create a Data Guard Standby
在12c之前創建物理備庫的方法有:
1.使用RMAN備份恢復方法;
2.在11g時可以選擇duplicate方式創建物理備庫;通過這種方式直接在線從主庫搭建起物理備庫。
到12cR2后,Oracle又提供更簡單的方式來創建物理備庫,就是本篇文章介紹的方式:即使用DBCA方式直接建立物理備庫。這個功能再次簡化了創建備庫的復雜度。
通過DBCA提供的參數createDuplicateDB,我們可以很容易的搭建一個物理備庫。其具體語法如下:
dbca -createDuplicateDB -gdbName global_database_name -primaryDBConnectionString easy_connect_string_to_primary -sid database_system_identifier [-createAsStandby [-dbUniqueName db_unique_name_for_standby]] [-customScripts scripts_list] [-datafileDestination data_files_directory] [-initParams initialization_parameters [-initParamsEscapeChar initialization_parameters_escape_character]] [-useWalletForDBCredentials {true | false} -dbCredentialsWalletPassword wallet_account_password -dbCredentialsWalletLocation wallet_files_directory]
雖然通過DBCA能非常簡單的創建一個物理備庫,但是要使用這個功能,必須滿足以下條件:
主庫必須是單機環境,非RAC數據庫;
主庫必須是非CDB環境;
在12c里非常重要的新特性之一就是多租戶環境,但是該特性不支持CDB環境的數據庫,同時主庫也不能是RAC環境。如果不滿足以上條件,在使用DBCA創建備庫的時候,會提示如下錯誤:
主庫是CDB環境,錯誤如下: [FATAL] [DBT-16057] Specified primary database is a container database (CDB). CAUSE: Duplicate database operation is supported only for non container databases. 主庫是RAC數據庫,錯誤如下: [FATAL] [DBT-16056] Specified primary database is not a Single Instance (SI) database. CAUSE: Duplicate database operation is supported only for SI databases.
也就說通過DBCA搭建出來的備庫也是一個單機非CDB的備庫,如果你想要搭建一個為RAC的備庫,則需要手動轉換或者使用Oracle Enterprise Manager Cloud Control來將備庫轉換為RAC數據庫。
接下來將演示如何使用DBCA來創建一個物理備庫。假定主備環境如下:
同時假設主備庫已經具備如下環境:
1.主庫是單機并且使用ASM;
2.主庫已經開啟了歸檔模式;
3.密碼文件和SPFILE都存儲在ASM中;
4.備庫同樣使用ASM存儲數據,且備庫端環境已經具備;
創建步驟如下:
1.在主庫開啟Force Logging
[oracle@dbpri]$ sqlplus / as sysdba SQL> alter database force logging; Database altered. SQL>
2.主庫創建Standby Redo logs
查看Redo log的大小:
[oracle@dbpri]$ sqlplus / as sysdba SQL> select thread#,group#,bytes/1024/1024 SIZE _MB, status from v$log; THREAD# GROUP# SIZE_MB STATUS ---------- ---------- -------------- ---------------- 1 1 100 CURRENT 1 2 100 INACTIVE 1 3 100 INACTIVE 1 4 100 INACTIVE 1 5 100 INACTIVE 1 6 100 INACTIVE
創建Standby redo logs:
[oracle@dbpri]$ sqlplus / as sysdba SQL> alter database add standby logfile thread 1 group 7 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 8 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 9 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 10 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 11 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 12 ('+DATADG') size 100M; Database altered. SQL> alter database add standby logfile thread 1 group 13 ('+DATADG') size 100M; Database altered. SQL>
當在主庫創建好 Standby redo logs 后,備庫也會自動創建。
3.創建網絡服務名
主庫tnsnames.ora
ordbpri = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL= TCP)(HOST=dbpri)(PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbpri) ) ) ordbstd = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd) (PORT=1521)))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbstd) ) ) ordbpri_local_listener = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbpri)(PORT=1521) ) ) )
備庫tnsnames.ora
ordbpri = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL= TCP)(HOST=dbpri)(PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbpri) ) ) ordbstd = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd) (PORT=1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ordbstd) ) ) ordbstd_local_listener = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS=(PROTOCOL = TCP)(HOST=dbstd)(PORT=1521) ) ) )
4.在備庫執行DBCA
[oracle@dbstd ~]$ dbca -silent -createDuplicateDB -gdbName ordbpri -sid ordbstd -sysPassword oracle -primaryDBConnectionString dbpri:1521/ordbpri -createAsStandby -dbUniqueName ordbstd –initParams db_create_file_dest=+DATADG, db_create_online_log_dest_1=+DATADG,local_listener=”ordbstd_local_listener” 輸出如下: Enter SYS user password: Listener config step 33% complete Auxiliary instance creation 66% complete RMAN duplicate 100% complete Look at the log file " /u01/app/oracle/product/12.2.0/dbhome_1/cfgtoollogs/dbca/ordbpri/ordbpri.log" for further details.
注:也可以使用自定義腳本,當備庫完成創建后,執行定制腳本。
5.在備庫完成環境配置
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=+DATADG VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ordbstd' scope=spfile; SQL> alter system set db_file_name_convert='+DATADG/ordbpri','+DATADG/ordbstd' scope=spfile; SQL> alter system set log_file_name_convert='+DATADG/ordbpri','+DATADG/ordbstd' scope=spfile; SQL> alter system set standby_file_management=auto scope=spfile; SQL> alter system set remote_listener=' dbstd:1521' scope=spfile; SQL> shutdown immediate SQL> startup SQL> alter system register;
注:在12c,可以嘗試使用DG Broker來進行Data Guard的管理和維護。
6.備庫創建密碼文件和SPFILE到ASM
[grid@dbstd ~]$ export ORACLE_SID=+ASM1 [grid@dbstd ~]$ export ORACLE_HOME=/u01/app/12.2.0.1/grid [grid@dbstd ~]$ export PATH=$ORACLE_HOME/bin:$PATH [grid@dbstd]$asmcmd –p ASMCMD [+] > mkdir DATADG /ORDBSTD/PASSWORD ASMCMD[+]>pwcopy /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/orapwordbstd +DATADG/ORDBSTD/PASSWORD/pwordbstd [oracle@dbstd]$ rm /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/orapwordbstd [oracle@dbstd ~]$ export ORACLE_HOME=/u01/app/12.2.0.1/dbhome_1 [oracle@dbstd ~]$ export ORACLE_SID=ordbstd [oracle@dbstd ~]$ export PATH=$ORACLE_HOME/bin:$PATH [oracle@dbstd]$ sqlplus / as sysdba SQL> create pfile='/tmp/pfilestd.ora' from spfile; SQL> create spfile='+DATADG/ORDBSTD/spfileordbstd.ora' from pfile='/tmp/pfilestd.ora'; [oracle@dbstd]$ rm /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/spfileordbstd.ora
7.備庫創建PFILE并且關閉備庫。
[oracle@dbstd]$echo “spfile='+DATADG/ORDBSTD/spfileordbstd.ora'” > /u01/app/oracle/product/12.2.0.1/dbhome_1/dbs/initordbstd.ora [oracle@dbstd] sqlplus / as sysdba SQL> shutdown immediate SQL>exit
8.將備庫注冊到Oracle Restart及啟動備庫。
[oracle@dbstd]$ srvctl add database -db ordbstd -oraclehome /u01/app/oracle/product/12.2.0.1/dbhome_1 -dbtype Single -instance ordbstd -node dbstd -dbname ordbpri -diskgroup DATADG -role physical_standby -spfile '+DATADG/ORDBSTD/spfileordbstd.ora' -pwfile '+DATADG/ORDBSTD/PASSWORD/pwordbstd' [oracle@dbstd]$ srvctl start database -db ordbstd
至此,完成了DBCA從單實例主庫到創建單實例備庫。
| 作者簡介
楊波,沃趣科技數據庫技術專家
主要參與公司產品實施、測試、維護以及優化。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。