PREPARE DATABASE FOR DATA GUARD

The PREPARE DATABASE FOR DATA GUARD command configures a database for use as either a primary or standby database in a Data Guard broker configuration. Database initialization parameters are set to recommended values.

Format

PREPARE DATABASE FOR DATA GUARD [WITH DB_UNIQUE_NAME IS <db_unique_name>] [DB_RECOVERY_FILE_DEST IS <directory_location>]  [DB_RECOVERY_FILE_DEST_SIZE is <size>] [BROKER_CONFIG_FILE_1 IS <broker_config_file_1_location>] [BROKER_CONFIG_FILE_2 IS <broker_config_file_2_location>] [RESTART] [no_srl];

Command Parameters

db_unique_name

The value for the DB_UNIQUE_NAME initialization parameter. If the initialization parameter has been set to a different value, the existing value is replaced with the value specified by db_unique_name. If this parameter is not specified, the DB_UNIQUE_NAME parameter is set to the value of the DBNAME parameter.

directory_location

The directory name for the DB_RECOVERY_FILE_DEST initialization parameter, which represents the fast recovery area location. The specified directory must be accessible by all instances of a RAC database.

This parameter can be omitted if a local archive destination is set. However, if the DB_RECOVERY_FILE_DEST initialization parameter has not been set and no local archive destination has been set, specifying this parameter is mandatory.

If directory_location is specified, a log_archive_dest_n initialization parameter is set to the value USE_DB_RECOVERY_FILE_DEST. This is done whether or not there is a local archive destination already set.

size

A size value for the DB_RECOVERY_FILE_DEST initialization parameter. This parameter is mandatory if the DB_RECOVERY_FILE_DEST is specified.

broker_config_file_1_location

A file location that is used to set the DG_BROKER_CONFIG_FILE1 initialization parameter. The file location specified must be accessible by all instances of a RAC database.

This is an optional command parameter.

broker_config_file_2_location

A file location that is used to set the DG_BROKER_CONFIG_FILE2initialization parameter. The file location specified must be accessible by all instances of a RAC database.

This is an optional command parameter.

restart
The RESTART keyword allows for automatic restart of the database if any static initialization parameters require a change, or if the database requires to be in MOUNTED mode to enable archive log mode. If omitted, and any static changes are required, the command will fail.
no_srl
When present, the standby redo logs are suppressed while running the rest of the prepare sequence.

Prerequisites

You must connect to the primary or standby database as a user with the SYSDBA privilege.

Usage Notes

  • Database versions starting from Oracle Database 12c Release 2 are supported.
  • For a single-instance database, if a server parameter file does not exist, it is created using the current in-memory parameter settings and stored in the default location.

  • This command sets the following initialization parameters, as per the values recommended for the Maximum Availability Architecture (MAA):

    • DB_FILES=1024
    • LOG_BUFFER=256M
    • DB_BLOCK_CHECKSUM=TYPICAL

      If this value is already set to FULL, the value is left unchanged.

    • DB_LOST_WRITE_PROTECT=TYPICAL

      If this value is already set to FULL, the value is left unchanged.

    • DB_FLASHBACK_RETENTION_TARGET=120

      If this parameter is already set to a non-default value, it is left unchanged.

    • PARALLEL_THREADS_PER_CPU=1
    • DG_BROKER_START=TRUE
  • This command enables archivelog mode, enables force logging, enables Flashback Database, and sets the RMAN archive log deletion policy to SHIPPED TO ALL STANDBY.

  • If standby redo logs do not exist, they are added. If the logs exist and are misconfigured, they are deleted and recreated.

  • This command validates that the target is either primary or physical standby, ensures the broker configuration artifacts (recovery area, broker config files, standby redo logs, flashback, restart) are provisioned for both database roles, and performs coordinated shutdown/restart when static parameters change.

  • This command tracks whether a standby was open before the command, and after configuration completes re-opens the database (and any RAC peers) only when that was the prior state, preserving the user’s operational mode instead of always forcing MOUNT.

  • Before setting archive destinations, this command checks for an existing local LAD and skips adding or enabling duplicate entries, aligning the command with environments that already have local archiving defined.

Command Example

The following example prepares a database with the name boston for use as a primary database. The recovery destination is $ORACLE_BASE_HOME/dbs.

DGMGRL> PREPARE DATABASE FOR DATA GUARD
	WITH DB_UNIQUE_NAME IS boston
	DB_RECOVERY_FILE_DEST IS "$ORACLE_BASE_HOME/dbs/"
	DB_RECOVERY_FILE_DEST_SIZE is "400G"
	DG_BROKER_CONFIG_FILE1 IS "$ORACLE_HOME/dbs/file1.dat"
	DG_BROKER_CONFIG_FILE2 IS "$ORACLE_HOME/dbs/file2.dat"
	RESTART;

Preparing database "boston" for Data Guard.
Creating server parameter file (SPFILE) from initialization parameter memory values.
Database must be restarted after creating the server parameter (SPFILE).
Shutting down database "boston".
Database closed.
Database dismounted.
ORACLE instance shut down.
Starting database "boston" to mounted mode.
ORACLE instance started.
Database mounted.
Server parameter file (SPFILE) is "ORACLE_BASE_HOME/dbs/spboston.ora".
Initialization parameter DB_UNIQUE_NAME set to 'boston'.
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 "boston".
Database dismounted.
ORACLE instance shut down.
Starting database "boston" to mounted mode.
ORACLE instance started.
Database mounted.
Initialization parameter DB_FLASHBACK_RETENTION_TARGET set to 120.
Initialization parameter DB_BLOCK_CHECKSUM set to 'TYPICAL'.
Initialization parameter DB_LOST_WRITE_PROTECT set to 'TYPICAL'.
Initialization parameter PARALLEL_THREADS_PER_CPU set to 1.
Removing RMAN archivelog deletion policy 1.
Removing RMAN archivelog deletion policy 2.
RMAN configuration archivelog deletion policy set to SHIPPED TO ALL STANDBY.
Initialization parameter DB_RECOVERY_FILE_DEST_SIZE set to '400G'.
Initialization parameter DB_RECOVERY_FILE_DEST set to 'ORACLE_BASE_HOME/dbs/'.
Initialization parameter DG_BROKER_START set to FALSE.
Initialization parameter DG_BROKER_CONFIG_FILE1 set to 'ORACLE_HOME/dbs/file1.dat'.
Initialization parameter DG_BROKER_CONFIG_FILE2 set to 'ORACLE_HOME/dbs/file2.dat'.
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'.
Initialization parameter STANDBY_FILE_MANAGEMENT set to 'MANUAL'.
Standby log group 4 will be dropped because it was not configured correctly.
Standby log group 3 will be dropped because it was not configured correctly.
Adding standby log group size 26214400 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.