
Time for action – verifying synchronization between the primary and standby databases
By using the following steps, you can control whether the standby database is synchronized with primary:
- On the standby database, query the
V$ARCHIVED_LOG
view for the archived and applied sequences.For the last archived sequence, use the following:
SQL> SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG; MAX(SEQUENCE#) -------------- 145
For the last applied sequence, use the following:
SQL> SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG WHERE APPLIED='YES'; MAX(SEQUENCE#) -------------- 144
From the preceding two queries, we see that the latest sequence,
145
, is being archived or written into the standby redo logfiles. There's expected to be a lag of one sequence between archived and applied columns. - Check the status of the latest log sequence.
SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; SEQUENCE# APPLIED ---------- --------- 140 YES 141 YES 142 YES 143 YES 144 YES 145 IN-MEMORY
The log sequence
145
is still being shipped. - On the primary database query for the last archived logfile, perform a couple of log switches and then monitor if those archives are transported and applied.
SQL> SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG; MAX(SEQUENCE#) -------------- 145
Perform log switches several times and check.
SQL> alter system switch logfile; System altered. SQL> SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG; MAX(SEQUENCE#) -------------- 148
- On the standby query for new archived logfiles and applied archived logfiles, query if the new archive log sequences are applied on standby.
SQL> SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; SEQUENCE# APPLIED ---------- --------- 143 YES 144 YES 145 YES 146 YES 147 YES 148 YES
The
APPLIED
column on standby will be very helpful to determine which sequence is generated and which sequences are applied. In the previous scenario, the archives generated on primary and archives applied on standby have the same sequence number; hence, standby is synchronized with the primary database.The value of the
APPLIED
column for the most recently received logfile will beIN-MEMORY
, orYES
if that logfile has been applied.
What just happened?
It's very important to know methods to verify synchronization between primary and standby databases. We've now seen one of these methods.