上一篇文章介紹了Data Guard 12cR2中3個(gè)特性,本篇文章將繼續(xù)介紹部分新特性。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名注冊(cè)、網(wǎng)頁(yè)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、懷柔網(wǎng)站維護(hù)、網(wǎng)站推廣。| Using DBCA to Create a Data Guard Standby
在12c之前創(chuàng)建物理備庫(kù)的方法有:
1.使用RMAN備份恢復(fù)方法;
2.在11g時(shí)可以選擇duplicate方式創(chuàng)建物理備庫(kù);通過(guò)這種方式直接在線從主庫(kù)搭建起物理備庫(kù)。
到12cR2后,Oracle又提供更簡(jiǎn)單的方式來(lái)創(chuàng)建物理備庫(kù),就是本篇文章介紹的方式:即使用DBCA方式直接建立物理備庫(kù)。這個(gè)功能再次簡(jiǎn)化了創(chuàng)建備庫(kù)的復(fù)雜度。
通過(guò)DBCA提供的參數(shù)createDuplicateDB,我們可以很容易的搭建一個(gè)物理備庫(kù)。其具體語(yǔ)法如下:
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]
雖然通過(guò)DBCA能非常簡(jiǎn)單的創(chuàng)建一個(gè)物理備庫(kù),但是要使用這個(gè)功能,必須滿足以下條件:
主庫(kù)必須是單機(jī)環(huán)境,非RAC數(shù)據(jù)庫(kù);
主庫(kù)必須是非CDB環(huán)境;
在12c里非常重要的新特性之一就是多租戶環(huán)境,但是該特性不支持CDB環(huán)境的數(shù)據(jù)庫(kù),同時(shí)主庫(kù)也不能是RAC環(huán)境。如果不滿足以上條件,在使用DBCA創(chuàng)建備庫(kù)的時(shí)候,會(huì)提示如下錯(cuò)誤:
主庫(kù)是CDB環(huán)境,錯(cuò)誤如下: [FATAL] [DBT-16057] Specified primary database is a container database (CDB). CAUSE: Duplicate database operation is supported only for non container databases. 主庫(kù)是RAC數(shù)據(jù)庫(kù),錯(cuò)誤如下: [FATAL] [DBT-16056] Specified primary database is not a Single Instance (SI) database. CAUSE: Duplicate database operation is supported only for SI databases.
也就說(shuō)通過(guò)DBCA搭建出來(lái)的備庫(kù)也是一個(gè)單機(jī)非CDB的備庫(kù),如果你想要搭建一個(gè)為RAC的備庫(kù),則需要手動(dòng)轉(zhuǎn)換或者使用Oracle Enterprise Manager Cloud Control來(lái)將備庫(kù)轉(zhuǎn)換為RAC數(shù)據(jù)庫(kù)。
接下來(lái)將演示如何使用DBCA來(lái)創(chuàng)建一個(gè)物理備庫(kù)。假定主備環(huán)境如下:
同時(shí)假設(shè)主備庫(kù)已經(jīng)具備如下環(huán)境:
1.主庫(kù)是單機(jī)并且使用ASM;
2.主庫(kù)已經(jīng)開啟了歸檔模式;
3.密碼文件和SPFILE都存儲(chǔ)在ASM中;
4.備庫(kù)同樣使用ASM存儲(chǔ)數(shù)據(jù),且備庫(kù)端環(huán)境已經(jīng)具備;
創(chuàng)建步驟如下:
1.在主庫(kù)開啟Force Logging
[oracle@dbpri]$ sqlplus / as sysdba SQL> alter database force logging; Database altered. SQL>
2.主庫(kù)創(chuàng)建Standby Redo logs
查看Redo log的大?。?/p>
[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
創(chuàng)建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>
當(dāng)在主庫(kù)創(chuàng)建好 Standby redo logs 后,備庫(kù)也會(huì)自動(dòng)創(chuàng)建。
3.創(chuàng)建網(wǎng)絡(luò)服務(wù)名
主庫(kù)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) ) ) )
備庫(kù)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.在備庫(kù)執(zhí)行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.
注:也可以使用自定義腳本,當(dāng)備庫(kù)完成創(chuàng)建后,執(zhí)行定制腳本。
5.在備庫(kù)完成環(huán)境配置
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來(lái)進(jìn)行Data Guard的管理和維護(hù)。
6.備庫(kù)創(chuàng)建密碼文件和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.備庫(kù)創(chuàng)建PFILE并且關(guān)閉備庫(kù)。
[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.將備庫(kù)注冊(cè)到Oracle Restart及啟動(dòng)備庫(kù)。
[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從單實(shí)例主庫(kù)到創(chuàng)建單實(shí)例備庫(kù)。
| 作者簡(jiǎn)介
楊波,沃趣科技數(shù)據(jù)庫(kù)技術(shù)專家
主要參與公司產(chǎn)品實(shí)施、測(cè)試、維護(hù)以及優(yōu)化。