Oracle Dataguard has his own command-line dgmgrl to check the whole dataguard configuration status.
At least you should check that the show configuration command returns SUCCESS.
This is an hypothetic script:
#!/bin/bash
export ORACLE_HOME=/u1/app/oracle/product/10.2.0
export ORACLE_SID=orcldg
result=`echo "show configuration;" | \
$ORACLE_HOME/bin/dgmgrl sys/strongpasswd | \
grep -A 1 "Current status for" | grep -v "Current status for"`
if [ "$result" = "SUCCESS" ] ; then
exit 0
else
exit 1
fi
Another script should check for the gap between production online log and the log stream received by the standby database. This can be accomplished with v$managed_standby view.
The Total Block Gap between production and standby can be calculated this way:
Sum all blocks from v$archived_logs where seq# between Current Standby Seq# and Current Production Seq#. Then add current block# of the production LGWR process and subtract current block# from RFS standby process. This gives you total blocks even if there is a log sequence gap between sites.
This is NOT the gap of online log APPLIED to the standby database. THIS IS THE GAP OF ONLINE LOG TRANSMITTED TO THE STANDBY RFS PROCESS and can be used to monitor your dataguard transmission from production to disaster recovery environment.
This is an excerpt of such script (please take care that it does not check against RFS failures, so it can fails when RFS is not alive):
#!/u1/app/oracle/product/10.2.0/perl/bin/perl -w
use DBI;
use DBD::Oracle qw(:ora_session_modes);
# DB connection #
my $prod = "orclprod";
my $stby = "orcldr";
my $prodh;
unless ($prodh = DBI->connect('dbi:Oracle:'.$prod,
'sys', 'strongpassword',
{PrintError=>0, AutoCommit => 0,
ora_session_mode => ORA_SYSDBA})) {
print "Error connecting to DB: $DBI::errstr\n";
exit(1);
}
$prodh->{RaiseError}=1;
my $stbyh;
unless ($stbyh = DBI->connect('dbi:Oracle:'.$stby,
'sys', 'strongpassword',
{PrintError=>0, AutoCommit => 0,
ora_session_mode => ORA_SYSDBA})) {
print "Error connecting to DB: $DBI::errstr\n";
$prodh->disconnect;
exit(1);
}
$stbyh->{RaiseError}=1;
my $sth;
### query prod
$sth = $prodh->prepare( < <EOSQL );
select SEQUENCE#, BLOCK# from v\$managed_standby
where process='LGWR'
EOSQL
$sth->execute();
my ($psequence, $pblock) = $sth->fetchrow_array();
$sth->finish();
### query stdby
$sth = $stbyh->prepare( < <EOSQL );
select SEQUENCE#, BLOCK# from v\$managed_standby
where process='RFS' and client_process='LGWR'
EOSQL
$sth->execute();
my ($ssequence, $sblock) = $sth->fetchrow_array();
$sth->finish();
printf ("PROD : %10d %10d\n", $psequence, $pblock);
printf ("STANDBY: %10d %10d\n", $ssequence, $sblock);
$sth = $stbyh->prepare( < <EOSQL );
select nvl(sum(blocks),0)
+ $pblock - $sblock as BLOCK_GAP
from v\$archived_log
where sequence# between $ssequence and $psequence
EOSQL
$sth->execute();
my ($blockgap) = $sth->fetchrow_array();
$sth->finish();
printf ("%-10d blocks gap\n", $blockgap);
$stbyh->disconnect;
$prodh->disconnect;
Any comment is appreciated!