转自 https://blog.51cto.com/8858975/1401988
监控脚本(注:这里没用Sendmail工具发送邮件,如果用的话需要修改)
$cat check_oracle_dg_delay.sh

#!/bin/sh
source ~/.bash_profile
#定义变量
v_datetime=`date +"%Y-%m-%d %H:%M:%S"`
v_username='oracle'
v_hostname=`hostname`
#获取IP地址
v_ip=`/sbin/ifconfig bond0|grep 'inet addr'|awk '{print $2}'|cut -d: -f2`
#发送人
v_sendmail='xxxxx@139.com'
#接收人,多个联系人用空格分开
v_receivemail='XXXXX@139.com XXXXX@163.com'
#路径
v_path="/home/${v_username}/scripts"
#####define tns#####
v_dbname='XXXXX'
v_standby_tns='xxxxx_dg'
#####报警阀值设置(单位:秒)#####
v_delay_time_warning=1800

#####Oracle DG 延时获取开始#####
sqlplus -S "/ as sysdba" <<EOF
--#####primary database####
col delay_time for 9999999999;
col tmp_delay_time new_val tmp_delay_time
set timing off time off verify off heading off trimout on trimspool on linesize 180;

spool ${v_path}/delay_time.log
select (to_date(to_char(scn_to_timestamp(current_scn),
'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') -
to_date(to_char(scn_to_timestamp
((select current_scn
from v\$database@phystandby.localdomain)),
'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss')) * 24 * 3600 tmp_delay_time
from v\$database;
spool off;

spool ${v_path}/delay_scn_and_time.log
col standby_current_scn for 999999999999999;
col primary_current_scn for 999999999999999;
col standby_current_time for a30;
col primary_current_time for a30;
col delay_time for 9999999999;
set heading on
select current_scn primary_current_scn,
(select current_scn from v\$database@phystandby.localdomain) standby_current_scn,
to_char(scn_to_timestamp(current_scn), 'yyyy-mm-dd hh24:mi:ss') primary_current_time,
to_char(scn_to_timestamp
((select current_scn from v\$database@phystandby.localdomain)),
'yyyy-mm-dd hh24:mi:ss') standby_current_time,
(to_date(to_char(scn_to_timestamp(current_scn),
'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') -
to_date(to_char(scn_to_timestamp
((select current_scn
from v\$database@phystandby.localdomain)),
'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss')) * 24 * 3600 "delay_time(s)"
from v\$database;
spool off;

exit
EOF
#####Oracle DG 延时获取结束#####

#####Oracle DG 延时时长提取#####
v_delay_time=`cat ${v_path}/delay_time.log|sed '/^$/d'|sed -e 's/[[:space:]][[:space:]]*/ /g'`
#####监控代码开始#####
if [ ${v_delay_time} -ge ${v_delay_time_warning} ] ; then

echo "############################" > ${v_path}/oracle_dg_delay.log
echo "USER: ${v_username}" >> ${v_path}/oracle_dg_delay.log
echo "HOSTNAME: ${v_hostname}" >> ${v_path}/oracle_dg_delay.log
echo "IP: ${v_ip}" >> ${v_path}/oracle_dg_delay.log
echo "############################" >> ${v_path}/oracle_dg_delay.log
cat ${v_path}/delay_scn_and_time.log >> ${v_path}/oracle_dg_delay.log
${v_path}/bsmtp -f ${v_sendmail} -h smtp.api.localdomain -s "${v_dbname} ORACLE DG DELAY ${v_delay_time}s WARNING!!! - ${v_datetime}" ${v_receivemail} < ${v_path}/oracle_dg_delay.log
fi
#####监控代码结束#####

2、配置crontab,每十分钟执行一次

$crontab -l

#oracle DG delay check
*/10 * * * * /home/oracle/scripts/check_oracle_dg_delay.sh >/dev/null 2>&1

[生产库实战] 采用存储过程对生产线历史表数据进行归档
https://blog.51cto.com/8858975/1785464

Oracle 11g DATAGUARD 同步延时监控脚本的更多相关文章

  1. Oracle 11g Dataguard参数详解

    https://www.jb51.net/article/52269.htm注:本文译自<Oracle Data Guard 11g Handbook> Page 78 – Page 88 ...

  2. Oracle 11g dataguard check RTA(real time apply)

    Oracle 11g dataguard check RTA(real time apply) 2017年8月24日 16:38 环境:oracle 11.2.0.1 OEL 5.8 注:以下操作都在 ...

  3. Oracle 11g DataGuard搭建(一) - 单节点到单节点

    (一)DataGuard概要 DataGuard中文称为”数据卫士“,提供了数据库高可用性.数据保护和灾难恢复的功能.DataGuard通过建立primary数据库和standby数据库来确立参照关系 ...

  4. Oracle 11g Dataguard 配置,维护与详解 (ADG)

    一.前言: 本手册主要记录如何配置,还介绍了配置原因,以及注意要点,已经主备切换,以及故障转移等重要操作步骤,我希望这个文章可以作为进行dataguard配置的一个参考手册. 二.前提 1.主库是归档 ...

  5. oracle 11g dataguard创建的简单方法

    oracle 10g可以通过基于备份的rman DUPLICATE实现dataguard,通过步骤需要对数据库进行备份,并在standby侧进行数据库的恢复.而到了11g,oracle推出了Dupli ...

  6. Oracle 11G DataGuard生产环境又一次启动具体过程

     场景,重新启动数据库,不重新启动linux系统,所以不用考虑监听程序,#linux输入lsnrctl start1 数据库关闭1.1 关闭主库SHUTDOWN IMMEDIATE; SQL> ...

  7. Oracle 11g 数据库自动备份执行脚本

    @echo offsetlocal enabledelayedexpansiontitle %date% %time:~,8% by LiaoNing Sunray Software Technolo ...

  8. oracle 11G dataguard 恢复

    检查主备机的sys 密码是否一致,忘记密码可以修改,同步 .alter user sys identified by xxx: orapwd file=oraxxx.ora password=admi ...

  9. Oracle 11g dataguard check real time apply

    2017年8月24日 16:38 环境:oracle 11.2.0.1 OEL-5.8 注:以下操作都在备库执行 总结方法: 1.FPYJ(125_7)@fpyj123> select open ...

随机推荐

  1. sshfs 相关材料索引

    这两天简单看了 sshfs 缓存相关的内容,下面对一些好的链接进行索引,防止以后忘了: OpenSSH: Difference between internal-sftp and sftp-serve ...

  2. 比较3个开源数据库:PostgreSQL,MariaDB和SQLite

    在现代企业技术世界里,开源软件已牢固地确立了自己作为不可忽视的,最大力量之一的地位.由于开源运动的出现,推动了几十年来的一些最著名的技术发展. 不难理解为什么:尽管基于Linux的开源网络标准可能不像 ...

  3. Mysql - 高可用方案之MMM(二)

    一.概述 上一篇博客中(https://www.cnblogs.com/ddzj01/p/11535796.html)介绍了如何搭建MMM架构,本文将通过实验介绍MMM架构的优缺点. 二.优点 1. ...

  4. k8s 使用 Init Container 确保依赖的服务已经启动

    k8s 使用 Init Container 确保依赖的服务已经启动 Intro 最近 helm 3 正式发布了,dotnetcore 3.1 也正式发布了,最近打算把我的活动室预约项目做一个升级,项目 ...

  5. Dev 日志 | 文章《快速体验知识图谱 OwnThink》中的技术问题

    社区小伙伴反馈在实践文章<使用图数据库 Nebula Graph 数据导入快速体验知识图谱 OwnThink>时,遇到了一些问题,Nebula Graph 将在本文对该文章中出现的问题进行 ...

  6. WPF之DataTemplateSelector的运用

    本文主要记录WPF中DataTemplateSelector的运用,数据模板选择器主要运用在一些项容器中用于根据不同的数据类型选择不同的DataTemplate,以便展示不同的数据.在此以在listb ...

  7. Nginx的安装及配置

    1.概述         Nginx是开源免费的一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.其特点是占有内存少,并发能力强,使用nginx网站用户有很多,如百 ...

  8. 分析Android APK-砸壳-Fdex2

    砸壳的工具千千万,但是FDex2 是最有能耐的,我尝试过各种壳,都是秒砸的.特别说明一下,360的壳,oncreated 方法还是空的,但是其他大部分内容还是有的,反正是可以参考一下的. 安装环境: ...

  9. Oracle 11g与12c的审计详解

    最近遇到一些脚本诱发的审计相关BUG,感觉有必要重新梳理一下11g与12c的审计模式,于是根据官网修正了一下以前的一篇笔记这里发出来. 一.审计功能的开启: SQL> show paramete ...

  10. MySQL优化/面试,看这一篇就够了

    原文链接:http://www.zhenganwen.top/articles/2018/12/25/1565048860202.html 作者:Anwen~链接:https://www.nowcod ...