Standby database creation

 #!/bin/bash


# Define variables (set these appropriately for your environment)

ORACLE_HOME="/u01/app/oracle/product/19.3.0/dbhome_1"

ORACLE_SID="pmjks"  # Standby SID for example

ORACLE_USER="oracle"

ORACLE_GROUP="dba"

STAGE_DIR="/u01/stage"

LOG_DIR="/tmp/tstgrade/${ORACLE_SID}"

DB_CREATEFILE_PATH="/u02/oradata"

DB_RECOFILE_DEST="/u03/fast_recovery_area"

TNS_PATH="/u01/app/oracle/network/admin"

PR_HOST="ora-x1"   # Primary hostname

SB_HOST="ora-x2"   # Standby hostname

LSNR_NAME="LISTENER"

DB_UNQ_NAME="mydb" # Database unique name

ROOT_USER="root"

ANSIBLE_DATE_TIME=$(date -Iseconds)


# Create log file directory

mkdir -p $LOG_DIR

chown $ORACLE_USER:$ORACLE_GROUP $LOG_DIR


# Create required directories on standby database server

echo "Creating required directories on standby database server..."

mkdir -p $STAGE_DIR $LOG_DIR $DB_CREATEFILE_PATH/$ORACLE_SID $DB_RECOFILE_DEST/$ORACLE_SID $DB_RECOFILE_DEST/$ORACLE_SID/pdbseed

chown -R $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR $LOG_DIR $DB_CREATEFILE_PATH/$ORACLE_SID $DB_RECOFILE_DEST/$ORACLE_SID


# Create required directories on primary database server

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Creating required directories on primary database server..."

  mkdir -p $STAGE_DIR $LOG_DIR $DB_RECOFILE_DEST/$ORACLE_SID

  chown -R $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR $LOG_DIR $DB_RECOFILE_DEST/$ORACLE_SID

fi


# Copy required scripts to primary database server

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Copying required scripts to primary database server..."

  cp /path/to/chkexistdg.sql /path/to/gensbredologs.sql /path/to/postcrpr.sql /path/to/dg_status.sql /path/to/tns_upd.sh /path/to/add_staticlsnr.sh $STAGE_DIR

  chown $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR/*

  chmod 0755 $STAGE_DIR/*

fi


# Copy required scripts to standby database server

if [ "$(hostname)" == "$SB_HOST" ]; then

  echo "Copying required scripts to standby database server..."

  cp /path/to/postcrsb.sql /path/to/tns_upd.sh /path/to/dg_status.sql /path/to/add_staticlsnr.sh $STAGE_DIR

  chown $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR/*

  chmod 0755 $STAGE_DIR/*

fi


# Template for post-sql on standby database

if [ "$(hostname)" == "$SB_HOST" ]; then

  echo "Setting up postcrsb.sql on standby database..."

  cp /path/to/postcrsb.sh.j2 $STAGE_DIR/postcrsb.sql

  chown $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR/postcrsb.sql

  chmod 0775 $STAGE_DIR/postcrsb.sql

fi


# Template for post-sql on primary database

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Setting up postcrpr.sql on primary database..."

  cp /path/to/postcrpr.sh.j2 $STAGE_DIR/postcrpr.sql

  chown $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR/postcrpr.sql

  chmod 0775 $STAGE_DIR/postcrpr.sql

fi


# Configure silent listener on standby host

if [ "$(hostname)" == "$SB_HOST" ]; then

  echo "Configuring silent listener on standby host..."

  cp /path/to/listener.rsp.19c.j2 $STAGE_DIR/silent-lsnr19c-config.rsp

  chown $ORACLE_USER:$ORACLE_GROUP $STAGE_DIR/silent-lsnr19c-config.rsp

  chmod 0775 $STAGE_DIR/silent-lsnr19c-config.rsp

  $ORACLE_HOME/bin/netca -silent -responseFile $STAGE_DIR/silent-lsnr19c-config.rsp

fi


# Execute TNS update for primary and standby databases

echo "Executing TNS update for primary and standby databases..."

$STAGE_DIR/tns_upd.sh $ORACLE_SID $PR_HOST $PORT $DB_UNQ_NAME $TNS_PATH

$STAGE_DIR/tns_upd.sh $ORACLE_SID $SB_HOST $PORT $DB_UNQ_NAME $TNS_PATH


# Add static listener for primary and standby

echo "Adding static listener for primary and standby databases..."

$STAGE_DIR/add_staticlsnr.sh ${ORACLE_SID}_DGMGRL $ORACLE_SID $LSNR_NAME $TNS_PATH


# Reload listener on primary database server

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Reloading listener on primary database server..."

  $ORACLE_HOME/bin/lsnrctl reload $LSNR_NAME

fi


# Setup force logging on primary

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Setting up force logging on primary database..."

  sqlplus / as sysdba <<EOF

  alter database force logging;

EOF

fi


# Ensure archiving is set to Fast Recovery Area on primary

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Setting archive log destination on primary..."

  sqlplus / as sysdba <<EOF

  alter system set log_archive_dest_1='location=$DB_RECOFILE_DEST valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=$DB_UNQ_NAME';

EOF

fi


# Execute standby redo logs script on primary

if [ "$(hostname)" == "$PR_HOST" ]; then

  echo "Executing standby redo logs script on primary database..."

  sqlplus / as sysdba <<EOF

  @$STAGE_DIR/gensbredologs.sql

EOF

fi


# Final status message

echo "This step completed the pre-configuration task for the physical standby database on $(hostname) at $ANSIBLE_DATE_TIME."

Comments

Popular posts from this blog

SQL Loader V3

Db Unix

Standby redo log add