Can I run a cron job as user Postgres?

I have a number of queries that need to run each night. I thought that I could do the following:

cd /var/discourse
./launcher enter app
su postgres
crontab -e
... add my tasks and save ...

but, I get an error:

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

Is this possible?

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

Check this example:

https://github.com/discourse/discourse-patreon/blob/master/app/jobs/scheduled/patreon_sync_patrons_to_groups.rb

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

https://github.com/discourse/discourse/blob/master/app/jobs/onceoff/clean_up_post_timings.rb

3 Likes

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 ?

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.