Scripts to start the Dataguard Standby Server after Windows system reboot occurred.
Problem:
When the window reboot occurred, the DR site of the data guard environment did not come up in recovery mode.
We get a gap between the physical and DR site.
Solution: Script OR TRIGGER to make the data guard standby site start in recovery mode on every window restart.
1. Placed the given below scripts on the 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;
OR
We can use this trigger directly on Standby Database to verify its primary or standby and close the instance and start the recovery.
CREATE OR REPLACE TRIGGER startup_mount
AFTER STARTUP ON DATABASE
DECLARE
role VARCHAR(30);
BEGIN
SELECT DATABASE_ROLE INTO role FROM V$DATABASE;
IF role != ‘PRIMARY’ THEN
execute IMMEDIATE ‘alter database close’;
execute IMMEDIATE ‘alter database recover managed standby database using current logfile disconnect from session’;
END IF;
END startup_mount;
/
2. Schedules this script in the Window Task Scheduler event “after startup”. Detailed steps are as follows:
a. Open the task scheduler in Windows and create essential task on it.

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

c. Select the start a program.

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

e. Click on properties and press the finish button.

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