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

查看:99
本文介绍了cron工作从debian上的postgres删除旧数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个每天晚上运行的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?

推荐答案

在大多数情况下,我更喜欢带有脚本的shell脚本吗?此处文档。 (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

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

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