Scripts to start the Dataguard after system reboot in Windows

Scripts to start the Dataguard after system reboot in Windows

Scripts to start the Dataguard Standby Server after Windows system reboot occurred.

Problem:
When system window system reboot occurred then the DR site of dataguard environment not come up in recovery mode.
We get gap in between the physical and DR site.

Solution:
Script to make the dataguard standby site start in recovery mode on every window restart.

1. Placed the given below scripts on folder as shown below:
Save the two files shown below in a folder script.

-- Save file as DGSTART.BAT
SQLPLUS SYS/PASSWORD AS SYSDBA @C:\SCRIPT\DGSTART.SQL > C:\SCRIPT\DBSTART.LOG

--Save file as DGSTART.SQL
STARTUP NOMOUNT;
ALTER DATABASE MOUNT;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS';
select sysdate from dual;
exit;

2. Schedules this script in Window Task Scheduler event “after startup”. Detailed steps as follows:

a. Open the task scheduler in windows and create basic task on it.

taskscheduler1

b. Select the Task Trigger –> When the Computer starts

tashscheduler2

c. Select the start a program.

taskscheduler3

d. Select your script by browser button and put location of script also in START IN(OPTIONAL) field.

taskcheduler4.PNG

e. Click on properties and press finish button.

taskscheduler5

f. Change the setting to RUN WHETHER USER IS LOGGED ON OR NOT.

taskscheduler6

11 thoughts on “Scripts to start the Dataguard after system reboot in Windows

  1. Paulo

    Thanks for sharing the script.
    We need to know first if data server is with database in standup mode or not. Maybe is in primary mode after switch…
    Am I right?
    Thanks

    Like

    Reply
  2. Anonymous

    Dear SandeepSingh DBA
    Thanks for your answer but you need to know where standby is to start that script… imagine that you implement that start script via Window Task Scheduler in a server that became primary?
    Thanks
    Paulo

    Like

    Reply
  3. SandeepSingh DBA Post author

    Yes thanks for update, you can put one check in between this script which let you check before firing command that database server is Standby or Primary. By using this statement:

    select database_role from v$database;

    Like

    Reply
  4. paulopires16

    Before open the databases, you need to know which is PRIMARY and STANDBY to run the STARTUP or STARTUP MOUNT command.
    So, you can’t run any command…
    Thanks
    Paulo

    Like

    Reply
  5. SandeepSingh DBA Post author

    SQL> shutdown abort
    ORACLE instance shut down.
    SQL> startup mount
    ORACLE instance started.

    Total System Global Area 1610609744 bytes
    Fixed Size 9028688 bytes
    Variable Size 1258291200 bytes
    Database Buffers 335544320 bytes
    Redo Buffers 7745536 bytes
    Database mounted.
    SQL> select database_role from v$database;

    DATABASE_ROLE
    —————-
    PRIMARY

    Like

    Reply
  6. paulopires16

    Dear SandeepSingh DBA,

    On primary is not a problem, you check witch is primary after mount mode and then “alter database open;”

    The problem is on standby. You mount standby and then, what you will do to set as standby?
    > ALTER DATABASE MOUNT STANDBY DATABASE; (you need this to knowledge by observer)
    > ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;

    Thanks

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.