Hi,
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.
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.
Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )
Dataguard Monitoring Scripts – v$dataguard_stats
Your dataguard is running but is there any lag ? You can learn below script.
set lines 1000 select name,value from v$dataguard_stats;
Standby ( Dataguard ) Lag
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;
Dataguard Stop / Start
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;
Dataguard ( Standby ) Processes
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');
Dataguard Parameters
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.
Useful Oracle RAC (Cluster Command) Scripts | Oracle DBA Scripts All in One -1
Do you want to learn Oracle Database Performance Tuning detailed, then read the following articles.
Performance Tuning and SQL Tuning Tutorial in the Oracle Database
I have heard of a command as this
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE; — this would open the DG Database in Read-Write mode.
Could you please clarify more on the below command ?
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Hi,
First command is not open database read write Mode. Second Command is start dataguard mrp (media Recovery process immediately ) process, thus lag will decrease and dataguard will be syncronized
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE
The above starts recovery process(MRP) and U can not write and read.
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
The above one starts MRP and U can do read only(such as run reports). The above only works only if U standby redo logs.
yeah it is true, I have also explained the Active standby on the other post.