Skip to Main Content
  • Questions
  • With Spool command generate output from two different query and if it match create dummy column "result" as match or successful

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Deepesh.

Asked: February 07, 2018 - 12:42 pm UTC

Last updated: February 09, 2018 - 2:18 am UTC

Version: 12.1.0.2.0

Viewed 1000+ times

You Asked

Hello Tom,

Required your help in below scenario:

Requirement : we have primary and DR server where we need to monitor synchronization between this two server.

Method used:
I have planned to use SPOOL command which connect to primary server first and then secondary server and get max(sequence#) with append command, but still i feel for improvement i.e. what i want if this sequence number matches then i want dummy column or file name should be changed to "InSync" or "matched" and if not matched then "outofSync" or "not match" but not able to get any post in this regards.

Please help me if we can do this then it would be really helpful for me.

Also any suggestion for monitoring sync process also be welcome.

Scripts:
set linesize 250
set pagesize 500
column sequence# format a12
set heading off
set markup html on
spool CheckDatabaseSyncStatus.html
set heading on
select max(sequence#) as "LAST LOG GENERATED AT PR" from V$log_history;
spool off
conn sys/ecpix@ecpixdr as sysdba
spool CheckDatabaseSyncStatus.html append;
select max(sequence#) "LAST LOG APPLIED AT DR" from V$log_history;
spool off
disconn
exit


Hoping for some valuable input as always all gets.

Thanks..

and Connor said...

If it was me, I'd be looking seriously at using DataGuard broker - it will help with all of this (and do a lot more as well).

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/dgbkr/examples-using-data-guard-broker-DGMGRL-utility.html#GUID-13FDC86F-A736-44F0-A2DD-33B7FF3067A7

In the interim, you can use a little post-processing to compare your data:

SQL> spool c:\temp\output.txt
SQL> select 'S='||max(sequence#) sby from v$log_history;

SBY
------------------------------------------
S=1697

SQL> conn / as sysdba
Connected.

SQL> select 'P='||max(sequence#) sby from v$log_history;

SBY
------------------------------------------
P=1697

SQL> spool off

$ egrep '(^S=|^P=)' output.txt | gawk -F= '{if ( NR == 1 ) {s=$2}}{if ( NR == 2 ){p=$2}}END{if ( s == p ) {print "OK"} else {print "FAIL"}}'
OK


I'd also look at keeping an eye on the following views:

v$dataguard_status
v$managed_standby
v$archived_log
v$dataguard_stats


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Deepesh Chothani, February 08, 2018 - 4:44 am UTC

Thank you TOM as always with valuable information.

But it was small information gap from my side, i am working on windows server so could you please help me accordingly.Linux or unix command will not work
Connor McDonald
February 09, 2018 - 2:18 am UTC

All of that I ran on Windows. I just use the Unix tools for Windows.

https://sourceforge.net/projects/unxutils/

More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database