查找最新事件时间在指定时间段内的任何行
这与 OpenNMS 相关,我正在尝试用 SQL 编写自动化。我有一个系统,每次备份成功时都会将事件发送到表。我想检测任何给定节点的备份是否过期。因此,例如(简化的)表如下所示:
nodeid, eventid, eventuei, eventtime
1 , 1 , backupOk, 09:20 15/12/09
2 , 2 , backupOk, 09:25 15/12/09
3 , 3 , backupOk, 09:30 15/12/09
1 , 4 , backupOk, 09:20 16/12/09
2 , 5 , backupOk, 09:25 16/12/09
2 , 6 , backupOk, 09:25 17/12/09
3 , 7 , backupOk, 09:30 17/12/09
所以我需要的是备份逾期 24 小时的节点 ID 列表(我猜根本没有发生备份,尽管该数据库中有些节点没有发生备份) t 得到备份(因为它们是不同类型的节点))。
The relates to OpenNMS where I'm trying to write an automation in SQL. I have a system which sends events to a table every time the backup succeeds. I want to detect if the backup is overdue for any given node. So for example the (simplified) table looks like:
nodeid, eventid, eventuei, eventtime
1 , 1 , backupOk, 09:20 15/12/09
2 , 2 , backupOk, 09:25 15/12/09
3 , 3 , backupOk, 09:30 15/12/09
1 , 4 , backupOk, 09:20 16/12/09
2 , 5 , backupOk, 09:25 16/12/09
2 , 6 , backupOk, 09:25 17/12/09
3 , 7 , backupOk, 09:30 17/12/09
So what I need is a list of nodeid's where the backup is overdue by 24 hours (and I guess where no backup has occurred at all, although there are nodes in this database that don't get backed up (as they are different types of node)).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您向我们展示的架构中获取未备份的节点列表是不可能的。
获取逾期 24 小时的节点列表很简单:
Getting list of nodes that were not backed up - from your schema that you showed us - is not possible.
Getting list of nodes that are 24 hours overdue is trivial:
以下 SQL 适用于 Oracle,但我假设 PostgreSQL 中也有类似的时间处理工具:
这将报告过去 48 小时内未运行备份的节点。
分享并享受。
The following SQL is for Oracle but I'll assume there are similar time-handling facilities in PostgreSQL:
This will report on nodes where a backup hasn't been run in the past 48 hours.
Share and enjoy.