转自 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. linux部署.net Core项目

    首篇笔记,多多关照.方便回忆和给新手指导,大神绕道 首先在Linux系统部署.net Core项目首先准备一个Linux系统的服务器,百度云,阿里云都行. 1.net core 部署在Linux系统上 ...

  2. 全文检索--Lucene & ElasticSearch

    全文检索--Lucene 2.1 全文检索和以前高级查询的比较 1.高级查询 缺点:1.like让数据库索引失效 2.每次查询都是查询数据库 ,如果访问的人比较多,压力也是比较大 2.全文检索框架:A ...

  3. cpv framework 0.1 正式发布 (C++ 网页框架)

    项目地址 https://github.com/cpv-project/cpv-framework 项目介绍 cpv framework 是一个 C++ 编写的网页框架,基于 seastar fram ...

  4. Spring Boot2解决idea console 控制台输出乱码

    Idea默认配置是采用GBK, 而项目工程文件采用的是UTF-8. 编码不一致,导致idea Console控制台输出乱码. 网上的解决方案,大都是直接修改Settings=>Editor=&g ...

  5. windows 本地链接 VMware虚拟机 redis服务

    使用本地Windows链接 VMware虚拟机 redis服务 我用的虚拟机系统是:windows Server 2012 先把Redis服务器拷贝到服务器并解压,目录如下 这里仅仅作为演示,所以就不 ...

  6. PlayJava Day030

    1.实例化Class类对象 //第一种,可靠高效 Class c0 = String.class ; //第二种,使用对象 Class c1 = "zhangsan".getCla ...

  7. pyecharts画图总结

    pyecharts 画图归纳 将本地文件导入到Pyecharts: test = open(filename, 'r') data = test.readlines() test.close() 如果 ...

  8. vue常见问题处理 -- 页面刷新时,如何保持原有vuex中的state信息

    一.页面刷新时,如何保持原有vuex中的state信息 页面刷新后,原有的 vuex 中的 state 会发生改变,如果在页面刷新之前,可以将 state 信息保存,页面重新加载时,再将该值赋给 st ...

  9. 从0使用Ruby on Rails打造企业级RESTful API项目实战之我的云音乐

    本节对我们项目实现的功能和知识点做一个简单的介绍,因为是RESTful API项目,所以对于后端来说基本上没有什么UI界面可展示,那我们就在关键的点,使用客户端(Android)实现的效果图. 课程简 ...

  10. iOS 中使用 webSocket

    iOS 中使用 webSocket 是服务器和app之间的一种通信方式 webSocket 实现了服务端推机制(主动向客户端发送消息).新的 web 浏览器全都支持 WebSocket,这使得它的使用 ...