Re: How to run a task continuously in the background - Mailing list pgsql-general

From Alan Hodgson
Subject Re: How to run a task continuously in the background
Date
Msg-id 927408b7f1a964134cea896d86db41b1ea0bd5ff.camel@lists.simkin.ca
Whole thread Raw
In response to Re: How to run a task continuously in the background  (Michael Nolan <htfoot@gmail.com>)
List pgsql-general
On Thu, 2019-07-11 at 11:19 -0500, Michael Nolan wrote:
A cron job will only run once a minute, not wake up every second.  But you could write a PHP program that does a one-second sleep before checking if there's something to do, and a batch job that runs periodically to see if the PHP program is running, and if not, launch it. 

That's how I handle a job that opens a tunnel from our PostgreSQL server to a MySQL server running at AWS so we can synchronize data between those two database servers.  It dies periodically for reasons we've never figured out, so every 5 minutes I check to make sure it's running. 

If you run such a job under systemd you can tell systemd to automatically restart it if it dies.

Alternate, the application monit is an older means of monitoring and restarting persistent processes, complete with email notifications.

This is quite a common system administration task. No need to roll your own.

pgsql-general by date:

Previous
From: Tim Clarke
Date:
Subject: Re: Restore database into azure PostgreSQL
Next
From: Wayne Mell
Date:
Subject: Postgresql and VBA - Connection Timeout