从 debian 上的 postgres 中删除旧数据的 cron 作业

编程入门 行业动态 更新时间:2024-10-22 11:25:02
本文介绍了从 debian 上的 postgres 中删除旧数据的 cron 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个每天晚上运行的 cron 并从我的数据库中删除一些数据(旧数据).我在 debian 上运行 postgres.我怎么做?我的服务器是tomcat6.有没有人有分步说明,包括执行此操作的脚本?

I need to create a cron that runs every night and remove some of the data (older ones) from my database. I am running postgres on debian. How do I do that? My server is tomcat6. Does anyone have a step by step instruction including script to do that?

推荐答案

在大多数情况下,我更喜欢带有 here-document 的 shell 脚本.(外壳变量在这里文档中很好地扩展):

in most cases, I prefer a shell script with an here-document. (shell-variables expand nicely in here-documents):

#!/bin/sh
PSQL=/local/postgres/bin/psql
SOME_VALUE=123

$PSQL my_database <<THE_END
DELETE FROM my_table
WHERE my_column <= $SOME_VALUE
    ;
THE_END

这篇关于从 debian 上的 postgres 中删除旧数据的 cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 04:43:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/679023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   数据   debian   postgres   cron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!