从 debian 上的 postgres 中删除旧数据的 cron 作业 [英] cron job to remove old data from postgres on debian

查看:20
本文介绍了从 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆