I will share all Oracle DBA Scripts related Dataguard in this post.
Oracle DBA ( Database Administrator ) needs useful scripts to monitor, analyze and check Oracle database for routine database operations and monitoring.
Oracle DBA Scripts All in One post will be updated with new Oracle DBA Scripts.
Before Oracle DBA Scripts, If you don’t know Oracle database and want to learn, click following link to start learning Oracle database with this tutorial.
Dataguard Monitoring Scripts
Your dataguard is running but is there any lag ? You can learn below script.
set lines 1000 select name,value from v$dataguard_stats;
If you want to know which archive sequence number comes from the Primary database lastly and which is last applied in Standby, you can learn the following script.
SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last in Sequence", APPL.SEQUENCE# "Last Applied Sequence", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference" FROM (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH, (SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL WHERE ARCH.THREAD# = APPL.THREAD# ORDER BY 1;
To stop dataguard you can use following query. When dataguard is stopped, MRP ( Media Recovery Process ) won’t run.
alter database recover managed standby database cancel;
To start dataguard you can use following query. When dataguard is started, MRP ( Media Recovery Process ) will run.
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
If you don’t want any lag you should start dataguard with using logfile option. You should add standby logs to the standby database in this case.
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
If you want to learn which of database is Standby and which of database is Primary, you can execute below query.
SELECT database_role, open_mode FROM v$database;
You can display the status of background processes in a standby database with below script.
select process, client_process,thread#,sequence#,status from v$managed_standby;
You can just want to see MRP process status then you can execute below script.
select process, client_process,thread#,sequence#,status from v$managed_standby where process like '%MRP%';
What is the MRP process waiting for status ? You can check with below script.
select a.event, a.wait_time, a.seconds_in_wait from gv$session_wait a, gv$session b where a.sid=b.sid and b.sid=(select SID from v$session where PADDR=(select PADDR from v$bgprocess where NAME='MRP0'));
To see the status of the switchover and the role of database which is in Standby or Primary state, execute following script.
select switchover_status,database_role from v$database;
To see archive gap in dataguard, execute following script.
SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
Below script provides information about approximate completion time of the recovery process
select to_char(start_time,'DD-MON-RR HH24:MI:SS') start_time,item,round(sofar/1024,2) "MB/Sec" from v$recovery_progress where (item='Active Apply Rate' or item='Average Apply Rate');
To see all parameters of Oracle dataguard, you can execute following query.
set linesize 500 pages 0 col value for a80 col name for a50 select name, value from v$parameter where name in ('db_name','db_unique_name','log_archive_config', 'log_archive_dest_1','log_archive_dest_2','log_archive_dest_3', 'log_archive_dest_state_1','log_archive_dest_state_2','log_archive_dest_state_3', 'remote_login_passwordfile', 'log_archive_format','log_archive_max_processes','fal_server','fal_client','db_file_name_convert', 'log_file_name_convert', 'standby_file_management') order by 1;
To see applied archivelogs in dataguard, execute following script.
select thread#,sequence#,first_time,next_time,applied from gv$archived_log where applied='YES';
Below script provides information about max sequence of dataguard
select thread#,max(sequence#) from gv$archived_log group by thread#;
You can access the First Oracle DBA scripts related to RAC with following link.