能否以用户 Postgres 运行 cron 作业?

我有一些查询需要每晚运行。我原本以为可以这样做:

cd /var/discourse
./launcher enter app
su postgres
crontab -e
... 添加我的任务并保存 ...

但我遇到了一个错误:

postgres@EN-Discourse-Forums-app:~$ crontab -e
crontab: installing new crontab
crontab: crontabs/postgres: rename: Operation not permitted
crontab: edits left in /tmp/crontab.7kGYwA/crontab

这可行吗?

The more “Discourse-way” of doing that would be creating a plugin with the queries as scheduled jobs.

Check this example:

Inside the execute block you can do anything, like this job who runs SQL:

Potentially, yes, but this doesn’t let others who may need to change the behavior of these queries and our servers use something they understand. It is very common to use CRON to run queries.

Did you read How to add a job to cron/anacron when creating Docker container ?