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.
b. Select the Task Trigger –> When the Computer starts
c. Select the start a program.
d. Select your script by browser button and put location of script also in START IN(OPTIONAL) field.
e. Click on properties and press finish button.
f. Change the setting to RUN WHETHER USER IS LOGGED ON OR NOT.
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
LikeLike
This script is only to start standby database.
LikeLike
Because primary database is start with window seevices but standby recovery is not started
LikeLike
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
LikeLike
Dear SandeepSingh DBA
Sorry, the last post was from me
Thanks
LikeLike
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;
LikeLike
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
LikeLike
you can run this command at mount stage.
LikeLike
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
LikeLike
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
LikeLike
You can also simply mount standy by with ALTER DATABASE MOUNT command and Check..thanks
LikeLike
As oracle database and there by database starts automatically. create this trigger in primary ;it should reflect in standby and do the job for you:
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
alter database close;
alter database recover managed standby database using current logfile disconnect from session;
END IF;
END;
/
LikeLike
Please read as “As oracle database windows service and …”
LikeLike
my bad the line should
IF role ‘PRIMARY’ THEN
LikeLike
my bad the line should
IF role !=‘PRIMARY’ THEN
LikeLike
Final version :
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;
/
LikeLike