数据库
首页 > 数据库> > [译] Data Guard:Oracle Database 21c 中的 PREPARE DATABASE FOR DATA GUARD 命令

[译] Data Guard:Oracle Database 21c 中的 PREPARE DATABASE FOR DATA GUARD 命令

作者:互联网

原文地址:https://oracle-base.com/articles/21c/data-guard-prepare-database-for-data-guard-21c
原文作者:Tim Hall

在 Oracle 数据库 21c 中配置 Data Guard 时,使用 PREPARE DATABASE FOR DATA GUARD 命令可以简化主数据库的设置。

目录

介绍

在配置 Data Guard 之前,主数据库的准备需要执行许多步骤。对于一个简单的单实例主数据库,可能需要以下步骤:

设置 DB_RECOVERY_FILE_DEST_SIZE 和 DB_RECOVERY_FILE_DEST 初始化参数:

alter system set db_recovery_file_dest_size=400g;
alter system set db_recovery_file_dest='/u01/app/oracle/fast_recovery_area';

启用归档日志模式并强制记录:

shutdown immediate;
startup mount;
alter database archivelog;
alter database open;

alter database force logging;

添加一些备用日志:

alter database add standby logfile thread 1 group 10 size 50m;
alter database add standby logfile thread 1 group 11 size 50m;
alter database add standby logfile thread 1 group 12 size 50m;
alter database add standby logfile thread 1 group 13 size 50m;

启用闪回数据库:

alter database flashback on;

设置 STANDBY_FILE_MANAGEMENT 初始化参数并启用代理:

alter system set standby_file_management=auto;
alter system set dg_broker_start=true;

在 Oracle 21c 中,可以使用 PREPARE DATABASE FOR DATA GUARD 命令执行以上这些步骤。

PREPARE DATABASE FOR DATA GUARD

我们通过 dgmgrl 与数据库建立连接,并且执行 HELP PREPARE 命令来查看语法:

$ dgmgrl /
DGMGRL for Linux: Release 21.0.0.0.0 - Production on Sun Feb 6 13:11:59 2022
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "cdb1"
Connected as SYSDG.
DGMGRL> help prepare

Prepare a primary database for a Data Guard environment.

Syntax:

  PREPARE DATABASE FOR DATA GUARD
    [WITH [DB_UNIQUE_NAME IS ]
          [DB_RECOVERY_FILE_DEST IS ]
          [DB_RECOVERY_FILE_DEST_SIZE IS ]
          [BROKER_CONFIG_FILE_1 IS ]
          [BROKER_CONFIG_FILE_2 IS ]];


DGMGRL>

这是我在 Vagrant 21c Data Guard 构建期间使用的命令示例:

dgmgrl / <<EOF
prepare database for data guard
  with db_unique_name is ${NODE1_DB_UNIQUE_NAME}
  db_recovery_file_dest is "${ORACLE_BASE}/fast_recovery_area"
  db_recovery_file_dest_size is 20g;
exit;
EOF

代入环境变量如下:

dgmgrl / <<EOF
prepare database for data guard
	with db_unique_name is cdb1
	db_recovery_file_dest is '/u01/app/oracle/fast_recovery_area'
	db_recovery_file_dest_size is 20G;
exit;
EOF

下面是命令执行创建的输出示例:

DGMGRL for Linux: Release 21.0.0.0.0 - Production on Sun Feb 6 14:03:10 2022
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All rights reserved.

Welcome to DGMGRL, type "help" for information.
Connected to "cdb1"
Connected as SYSDG.
DGMGRL> > > > Preparing database "cdb1" for Data Guard.
Initialization parameter DB_FILES set to 1024.
Initialization parameter LOG_BUFFER set to 268435456.
Primary database must be restarted after setting static initialization parameters.
Primary database must be restarted to enable archivelog mode.
Shutting down database "cdb1".
Database closed.
Database dismounted.
ORACLE instance shut down.
Starting database "cdb1" to mounted mode.
ORACLE instance started.
Database mounted.
Initialization parameter DB_FLASHBACK_RETENTION_TARGET set to 120.
Initialization parameter DB_LOST_WRITE_PROTECT set to 'TYPICAL'.
RMAN configuration archivelog deletion policy set to SHIPPED TO ALL STANDBY.
Initialization parameter DB_RECOVERY_FILE_DEST_SIZE set to '20g'.
Initialization parameter DB_RECOVERY_FILE_DEST set to '/u01/app/oracle/fast_recovery_area'.
LOG_ARCHIVE_DEST_n initialization parameter already set for local archival.
Initialization parameter LOG_ARCHIVE_DEST_2 set to 'location=use_db_recovery_file_dest valid_for=(all_logfiles, all_roles)'.
Initialization parameter LOG_ARCHIVE_DEST_STATE_2 set to 'Enable'.
Adding standby log group size 52428800 and assigning it to thread 1.
Adding standby log group size 52428800 and assigning it to thread 1.
Adding standby log group size 52428800 and assigning it to thread 1.
Initialization parameter STANDBY_FILE_MANAGEMENT set to 'AUTO'.
Initialization parameter DG_BROKER_START set to TRUE.
Database set to FORCE LOGGING.
Database set to ARCHIVELOG.
Database set to FLASHBACK ON.
Database opened.
DGMGRL>

通过以上输出结果,我们可以看到执行了常见的设置任务,并且设置了一些额外的初始化参数:

DB_FILES=1024
LOG_BUFFER=256M
DB_BLOCK_CHECKSUM=TYPICAL          # Unchanged if FULL
DB_LOST_WRITE_PROTECT=TYPICAL      # Unchanged if FULL
DB_FLASHBACK_RETENTION_TARGET=120  # Unchanged if non-default
PARALLEL_THREADS_PER_CPU=1
DG_BROKER_START=TRUE

当然了,还有一些其他的事项需要注意:

参考官方文档:PREPARE DATABASE FOR DATA GUARD

译者备注:整体看起来并不实用,并且需要配合使用 DGMGRL 来使用,期待后续优化,当然以上这些命令也完全可以自行写脚本来实现。

标签:set,PREPARE,database,parameter,Database,DB,FILE,DATA,alter
来源: https://blog.csdn.net/m0_50546016/article/details/122819219