配置 Oracle Data Guard

此手册提供了用于帮助您配置 Oracle Data Guard 环境的脚本。这些脚本使用 restore from service 功能和 Oracle Data Guard 中介为现有主数据库设置备用数据库。

dg-setup-scripts 使用 DG_properties.ini 文件定义主环境和备用环境。

这些脚本将创建 2 个 tar 文件、主密码文件的 tar 和主 Transparent Data Encryption (TDE) wallet 的 tar,您将该文件复制到备用数据库节点。

脚本不会对操作系统进行更改,例如 net.core.rmem_maxnet.core.wmem_max 或最大传输单元 (Maximum Transmission Unit,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(备用环境属性)”部分并更改参数以定义备用系统环境。
    ########################################################################################################
    # 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 OS 用户。
  3. 将以下文件上载到新的辅助数据库主机:
    • 3_dataguardit_standby_root.sh:上载到所有数据库节点。
    • DG_properties.ini:上载到所有数据库节点。
  4. 对于辅助数据库主机或主机,将脚本的执行权限授予 root OS 用户。

为主数据库准备 Oracle Data Guard 参数

在配置 Oracle Data Guard 之前,在主数据库上设置 Oracle Maximum Availability Architecture (MAA) 建议的 Oracle Data Guard 参数。1_prepare_primary_maa_parameters.sh 脚本为 Oracle Data Guard 配置建议的 MAA 参数并创建备用日志文件。

MAA 为 Oracle 数据库提供了架构、配置和生命周期实践,可以为驻留在内部部署、云或混合配置的数据库提供高可用性服务级别。

该脚本设置以下 MAA 建议的参数值:
  • 导出 DB_FLASHBACK_RETENTION_TARGET=1440
  • 导出 DB_BLOCK_CHECKSUM=FULL
  • 导出 DB_BLOCK_CHECKING=FULL
  • 导出 DB_LOST_WRITE_PROTECT=TYPICAL
  • 导出 LOG_BUFFER=256M
  • 导出 STANDBY_FILE_MANAGEMENT=AUTO

注意:

根据 MAA 最佳实践,参数 DB_BLOCK_CHECKING 应设置为主数据库中的 MEDIUMFULL。该脚本将其设置为 FULL。如果主数据库上启用 DB_BLOCK_CHECKINGMEDIUMFULL 的性能开销不可接受,则仅为备用数据库将 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 文件
  • 包含 TDE wallet 的 TAR 文件(仅当使用 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 文件,并为 Transparent Data Encryption (TDE) wallet 创建 tar 文件(如果使用 TDE)。
  4. 如果主数据库是 Oracle Real Application Clusters (Oracle RAC) 数据库,则在 Node2 中运行该脚本。
  5. (建议)设置 net.core.rmem_maxnet.core.wmem_max 的操作系统参数以优化 redo transport
    如果是 Oracle RAC,则在两个节点中优化。
    有关 MAA 建议的链接,请参阅“浏览更多”。
  6. (建议)设置最大传输单元 (Maximum Transmission Unit,MTU) 以优化 redo transport
    如果是 Oracle RAC,则在两个节点中优化。
    有关 MAA 建议的链接,请参阅“浏览更多”。

复制输出文件

复制从主数据库节点生成的输出 tar 文件并将其上载到辅助数据库主机。如果您具有 Oracle RAC,则 tar 文件将在 Node1 中创建。将 tar 文件上载到辅助主机中的两个节点。

确保将 tar 文件放置在 DG_properties.ini 文件中定义的属性 INPUT_PASWORD_TARINPUT_WALLET_TAR(使用 TDE 时)所指示的位置。

Oracle Data Guard 准备辅助系统

准备新的辅助(备用)主机,创建备用数据库,并在辅助数据库节点中配置 Oracle Data Guard 中介。

3_dataguardit_standby_root.sh 脚本通过删除现有数据库并配置所需的构件(TNS 别名、NET 加密、密码文件和透明数据加密 (Transparent Data Encryption,TDE) wallet),准备新的备用数据库主机。然后,它将使用 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. (建议)设置最大传输单元 (Maximum Transmission Unit,MTU) 以优化 redo transport
    如果是 Oracle RAC,则在两个节点中优化。
    有关 MAA 建议的链接,请参阅“浏览更多”。

为新备用数据库添加 TNS 条目

如果将新的备用数据库添加到现有的 Oracle Data Guard 实例 (ADDITIONAL_STANDBY=YES),则在新的备用数据库 tnsnames.ora 文件中添加指向以前现有备用数据库的 TNS 条目,反之亦然。 确保备用数据库能够彼此连接到监听程序端口。