設定 Oracle Data Guard

此電子書提供協助設定 Oracle Data Guard 環境的命令檔。這些命令檔會使用 restore from service 功能和 Oracle Data Guard 中介來設定現有主要資料庫的待命資料庫。

dg-setup-scripts 使用 DG_properties.ini 檔案定義主要和待命環境。

命令檔會建立 2 個 tar 檔案、主要密碼檔的 tar,以及主要通透資料加密 (TDE) 公事包,這些檔案會複製到待命資料庫節點。

程序檔不會變更作業系統,例如 net.core.rmem_maxnet.core.wmem_max,或最大傳輸單位 (MTU)。最佳做法是調整 net.core.rmem_maxnet.core.wmem_max 以取得最佳的重做傳輸。

下列作業說明如何執行命令檔,為您的資料庫設定 Oracle Data Guard

定義 Oracle Data Guard 的環境變數

使用 DG_properties.ini 檔案來準備 Oracle Data Guard 組態的主要系統。程序檔使用 DG_properties.ini 中的參數來設定主要和待命系統。檔案包含指令碼所需的所有輸入參數。請參閱瀏覽更多中 DG_properties.ini 檔案的範例。

dg-setup-scripts zip 檔案中有範例 DG_properties.ini 檔案。您可以使用環境的值自訂檔案。

  1. 下載 dg-setup-scripts zip 檔案並擷取內容。
  2. 編輯 Linux 作業系統中的範例 DG_properties.ini 特性檔,以使用您環境的特定值自訂檔案。
    在 Linux 中編輯可避免在行尾端發生編碼相關問題,例如取得 Windows CRLF。
  3. 如果系統是 Oracle Real Application Clusters (Oracle RAC) ,且密碼檔位於 Oracle Automatic Storage Management (Oracle ASM) ,請編輯「一般特性」區段以定義匯出參數。
    ########################################################################################################
    # GENERAL PROPERTIES
    ########################################################################################################
    export ORACLE_OSUSER=oracle
    export ORACLE_OSGROUP=oinstall
    export GRID_OSUSER=grid
    export GRID_HOME=/u01/app/19.0.0.0/grid
    export ORACLE_HOME=/u01/app/oracle/product/18.0.0.0/dbhome_1
    export ORACLE_BASE=/u01/app/oracle
    
    export DB_NAME=DBTEST4	    # The database name (the value of db parameter db_name)
    export SYS_USERNAME=sys
    
    export RAC=NO	             # Set to YES (if DB is a RAC) or to NO (if single instance DB)
    export PASSWORD_FILE_IN_ASM=YES  # Set to YES when the password file is placed in ASM (in case of RAC, it will always be placed in ASM).
    export ADDITIONAL_STANDBY=NO     # Set to YES only if the primary db has another standby database already configured, and you are using the scripts to add a second standby.
  4. 編輯「主要環境特性」區段並變更參數以定義主要系統環境。
    #########################################################################################################
    # PRIMARY ENV PROPERTIES
    #########################################################################################################
    export A_PORT=1521					# The primary listener's port (scan's listener port if RAC)
    export A_SERVICE=ORCL_PRI.primarydomainexample.com	# The default CDB service name in primary (format is <db_unique_name>.<primary_domain>) 
    export A_DBNM=ORCL_PRI					# The DB UNIQUE NAME of primary DB
    
    # For single instance (will be ignored if RAC=YES)
    	export A_DB_IP=10.10.10.10			# Provide the primary listener's IP. This needs to be reachable from the standby DB.
    
    # For RAC (will be ignored if RAC=NO)
    	# Specify the PRIMARY RAC's scan IPs and scan address name
    	export A_SCAN_IP1=10.10.10.1
    	export A_SCAN_IP2=10.10.10.2
    	export A_SCAN_IP3=10.10.10.3
    	export A_SCAN_ADDRESS=primary-scan.primarydomainexample.com
    	# Provide the ORACLE_SID of the primary RAC instances
    	export A_SID1=ORCL1
    	export A_SID2=ORCL2
    
    export A_FILE_DEST="+DATA"              # the value of db_create_file_dest db parameter in primary DB
    export A_ONLINE_LOG_DEST1="+RECO"       # the value of db_create_online_log_dest_1 parameter in primary DB
    export A_RECOVERY_FILE_DEST="+RECO"     # the value of db_recovery_file_dest parameter in primary DB
    
    # Other properties required by primary setup script
    export TDE_LOC=/opt/oracle/dcs/commonstore/wallets/tde/${A_DBNM}	# The the TDE wallet folder in primary (where the .p12 file is located). Leave it EMPTY if TDE is not used.
    export CREATE_PASSWORD_FILE=YES                                         # If password file already exists in primary and you do not want to override it, set this to NO.
    export OUTPUT_WALLET_TAR=/tmp/PRIMARY_TDE_WALLET.GZ         		# Absolute file name for the output tar file that will be generated in primary, containing the primary TDE wallet.
    export OUTPUT_PASWORD_TAR=/tmp/PRIMARY_PASSWORD_FILE.GZ        		# Absolute file name for the output tar file that will be generated in primary, containing the primary password file.
    
  5. 編輯「待命環境特性」區段並變更參數以定義待命系統環境。
    ########################################################################################################
    # STANDBY ENV PROPERTIES
    ########################################################################################################
    export B_PORT=1521							# The standby listener's port (scan's listener port if RAC)
    export B_SERVICE=ORCL_STBY.standbydomainexample.com			# The default CDB service name in standby (format is <db_unique_name>.<secondary_domain>)
    export B_DBNM=ORCL_STBY							# The DB UNIQUE NAME of standby DB
    
    # For single instance (will be ignored if RAC=YES)
    	export B_DB_IP=10.20.20.20	# Provide the primary listener's IP. This needs to be reachable from the standby DB
    
    # For RAC (will be ignored if RAC=NO) 
    	# Specify STANDBY RAC's scan IPs and scan address name
    	export B_SCAN_IP1=10.20.20.1
    	export B_SCAN_IP2=10.20.20.2
    	export B_SCAN_IP3=10.20.20.3
    	export B_SCAN_ADDRESS=standby-scan.standbydomainexample.com
    	# Standby node's VIPs (provide the IPS, not the names)
    	export B_VIP1=10.20.20.10
    	export B_VIP2=10.20.20.20
    	# Provide the ORACLE_SID of the standby RAC instances
    	export B_SID1=ORCL1
    	export B_SID2=ORCL2
    	# (normally only needed in Exadata) Provide interconnect IPs if they must be specified in the parameter cluster_interconnects. Leave them empty if cluster_interconnects is empty.
            export B_INTERCONNECT_IP1=
            export B_INTERCONNECT_IP2=
    
    
    export B_FILE_DEST="+DATA"              # the value of db_create_file_dest db parameter in standby DB
    export B_ONLINE_LOG_DEST1="+RECO"       # the value of db_create_online_log_dest_1 parameter in standby DB
    export B_RECOVERY_FILE_DEST="+RECO"     # the value of db_recovery_file_dest parameter in standby DB
    
    # Other properties required by the standby setup script
    export INPUT_WALLET_TAR=/tmp/PRIMARY_TDE_WALLET.GZ		   # Absolute file name for the input tar file that contains the primary TDE wallet.
    export INPUT_PASWORD_TAR=/tmp/PRIMARY_PASSWORD_FILE.GZ	      # Absolute file name for the input tar file that contains the primary password file.
    export B_TDE_LOC=/opt/oracle/dcs/commonstore/wallets/$B_DBNM/tde   # Absolute  path where the wallet files (.p12) will be created in standby hosts. 
    # Verify which is the value used by your system, it may differ. Leave it empty if TDE is not used.

上傳命令檔

將命令檔上傳至主要和次要資料庫主機,如下所示:

  1. 將下列命令檔和檔案上傳至 primary 資料庫主機或主機:
    • 1_prepare_primary_maa_parameters.sh:上傳至資料庫主機 1 (單一執行處理或 Oracle RAC)。
    • 2_dataguardit_primary.sh:上傳至所有資料庫節點。
    • create_pw_tar_from_asm_root.sh:上傳至所有資料庫節點。
    • DG_properties.ini:上傳至所有資料庫節點。
  2. 針對主要資料庫主機或主機,將命令檔上的執行權限授予所有節點的 oracle 作業系統使用者。
  3. 將下列檔案上傳至新的次要資料庫主機或主機:
    • 3_dataguardit_standby_root.sh:上傳至所有資料庫節點。
    • DG_properties.ini:上傳至所有資料庫節點。
  4. 對於次要資料庫主機或主機,將命令檔上的執行權限授予 root 作業系統使用者。

準備主要資料庫的 Oracle Data Guard 參數

先在主要資料庫上設定 Oracle Maximum Availability Architecture (MAA) 建議的 Oracle Data Guard 參數,再設定 Oracle Data Guard1_prepare_primary_maa_parameters.sh 命令檔會為 Oracle Data Guard 設定建議的 MAA 參數,並建立待命日誌檔。

MAA 針對 Oracle 資料庫提供架構、組態及生命週期最佳做法,並針對位於內部部署、雲端或混合式組態的資料庫啟用高可用性服務層次。

命令檔會設定下列 MAA 建議參數值:
  • 匯出 DB_FLASHBACK_RETENTION_TARGET=1440
  • 匯出 DB_BLOCK_CHECKSUM= 完整
  • 匯出 DB_BLOCK_CHECKING= 完整
  • 匯出 DB_LOST_WRITE_PROTECT=TYPICAL
  • 匯出 LOG_BUFFER=256M
  • 匯出 STANDBY_FILE_MANAGEMENT=AUTO

注意:

依據 MAA 最佳做法,主要資料庫中的參數 DB_BLOCK_CHECKING 應設為 MEDIUMFULL。命令檔會將它設為 FULL。如果主要資料庫無法接受將 DB_BLOCK_CHECKING 啟用至 MEDIUMFULL 的效能超載,請只為待命資料庫將 DB_BLOCK_CHECKING 設為 MEDIUMFULL

請先執行命令檔來設定參數,再設定 Oracle Data Guard。只執行此命令檔一次,無論主要是 Oracle Real Application Clusters (Oracle RAC) 或單一執行處理資料庫。

  1. oracle 使用者身分登入主要資料庫節點。
  2. 針對單一執行處理資料庫,在主要資料庫主機中執行 1_prepare_primary_maa_parameters.sh 命令檔,若為 Oracle Real Application Clusters (Oracle RAC) ,請執行 Node1 命令檔。
    指令碼將會提示輸入 sys 使用者的密碼。

設定 MAA 參數之後,命令檔會在 ONLINE_LOG_DEST1 目錄中建立待命日誌。待命日誌的大小與線上日誌 (REDOLOG_SIZE) 相同。它們具有一個以上的群組,但相同的執行緒數目。

準備用於 Oracle Data Guard 的主要系統

準備 Oracle Data Guard 組態的主要主機,並建立待命資料庫主機之後需要的輸出檔案。

2_dataguardit_primary.sh 程序檔會建立下列輸出檔案:
  • 包含密碼檔的 TAR 檔案
  • TAR 檔案包含 TDE 公事包 (僅在使用 TDE 加密時)。
  1. oracle 使用者身分登入主要資料庫節點。
  2. 驗證 DG_properties.ini 檔案與 2_dataguardit_primary.sh 指令碼位於相同的資料夾中,且已使用環境值正確地自訂該檔案。
  3. 在主要資料庫 Node1 中執行 2_dataguardit_primary.sh 命令檔。

    指令碼將會提示輸入 sys 使用者的密碼。

    當密碼檔儲存在 ASM 中時,命令檔會要求使用者執行 create_pw_tar_from_asm_root.sh 命令檔。

    此命令檔會為密碼檔建立一個 tar 檔案,以及通透資料加密 (TDE) 公事包的 tar 檔案 (如果使用 TDE)。
  4. 如果主要資料庫是 Oracle Real Application Clusters (Oracle RAC) 資料庫,則請在 Node2 中執行該命令檔。
  5. (建議使用) 設定 net.core.rmem_maxnet.core.wmem_max 的作業系統參數以最佳化 redo transport
    如果是 Oracle RAC,則會在兩個節點中進行最佳化。
    請參閱「深入瞭解」以取得 MAA 建議的連結。
  6. (建議使用) 設定最大傳輸單位 (MTU) 以最佳化 redo transport
    如果是 Oracle RAC,則會在兩個節點中進行最佳化。
    請參閱「深入瞭解」以取得 MAA 建議的連結。

複製輸出檔

複製從主要資料庫節點產生的輸出 tar 檔,並將其上傳至次要資料庫主機。如果您有 Oracle RAC,則會在 Node1 中建立 tar 檔案。將 tar 檔上傳至次要主機中的兩個節點。

確定將 tar 檔案放置在 DG_properties.ini 檔案中定義的特性 INPUT_PASWORD_TARINPUT_WALLET_TAR (使用 TDE 時) 所指示的位置。

準備 Oracle Data Guard 的次要系統

準備新的次要 (待命) 主機、建立待命資料庫,以及在次要資料庫節點中設定 Oracle Data Guard 中介。

3_dataguardit_standby_root.sh 命令檔會刪除現有資料庫並設定必要的使用者自建物件 (TNS 別名、NET 加密、密碼檔以及通透資料加密 (TDE) 公事包),以準備新的待命資料庫主機。接著,它會使用 Oracle Recovery Manager (RMAN) restore from service 功能來建立和設定待命資料庫,然後設定 Oracle Data Guard 中介。

3_dataguardit_standby_root.sh 程序檔使用您在 DG_properties.ini 檔案中定義的環境變數。如果次要是 Oracle RAC 資料庫,則請在兩個節點中執行該命令檔。當命令檔在 Node1 中執行,且步驟子集在 Node2 中執行時,會執行大部分的動作。指令碼在 Node1 中完成前,請勿在 Node2 中執行該程序檔。

  1. root 使用者身分登入次要資料庫節點。
    若為 Oracle RAC,請登入 Node1。
  2. 在上傳命令檔的目錄中尋找 3_dataguardit_standby_root.sh 命令檔。
  3. 確認 DG_properties.ini 檔案與 3_dataguardit_standby_root.sh 指令碼位於相同的資料夾中,且指令碼中的自訂內容正確。
  4. 執行 3_dataguardit_standby_root.sh 程序檔。
    指令碼將會提示輸入 sys 使用者的密碼。
  5. 如果您有 Oracle RAC,請以 root 身分登入 Node2,然後在 Node1 中完成後,在「節點 2」中執行 3_dataguardit_standby_root.sh 命令檔。
  6. (建議使用) 設定 net.core.rmem_maxnet.core.wmem_max 的作業系統參數以最佳化 redo transport
    如果是 Oracle RAC,則會在兩個節點中進行最佳化。
    請參閱「深入瞭解」以取得 Oracle Maximum Availability Architecture (MAA) 建議的連結。
  7. (建議使用) 設定最大傳輸單位 (MTU) 以最佳化 redo transport
    如果是 Oracle RAC,則會在兩個節點中進行最佳化。
    請參閱「深入瞭解」以取得 MAA 建議的連結。

為新的待命資料庫新增 TNS 項目

如果您已將新的待命資料庫新增至現有的 Oracle Data Guard 執行處理 (ADDITIONAL_STANDBY=YES),則請在新的待命資料庫 tnsnames.ora 檔案中,新增指向先前現有待命資料庫、指向先前現有待命資料庫之 TNS 項目,反之亦然。 確定待命資料庫可以互相連線至監聽器連接埠。