From: Weatherby,Gerard <gweatherby@uchc.edu>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: How to run a task continuously in the background
Date: Tue, 16 Jul 2019 11:58:33 +0000
Message-ID: <1563278313157.67005@uchc.edu> (raw)
In-Reply-To: <14555705-8010-4A73-8501-EA07B285E1BA@mikatiming.de>
References: <7932668C-EA48-436B-AA15-DB7C8446D57F@mikatiming.de>
<E9FA92C2921F31408041863B74EE4C2001BD810545@CCPMAILDAG03.cantab.local>
<CAOzAquKb+O3iu0pVBonDDSS8SH=a4Wa4hmYFxAbTwUCi7Hxjhg@mail.gmail.com>
<D49B7AAD-5EC3-4D62-A263-E22E6633C807@mikatiming.de>
<CAKoxK+7x4wEA-AMocZ00b8pAcBe2xZMq_6s8xsKPTWq7tGPdig@mail.gmail.com>
<14555705-8010-4A73-8501-EA07B285E1BA@mikatiming.de>
We used a trigger that called pg_notify (https://www.postgresql.org/docs/9.5/sql-notify.html?) and then had another
process that LISTENed for notifications.
--
Gerard Weatherby| Application Architect
NMRbox | Department of Molecular Biology and Biophysics | UConn Health
263 Farmington Avenue, Farmington, CT 06030-6406
Phone: 860 679 8484
uchc.edu
________________________________
From: Dirk Mika <Dirk.Mika@mikatiming.de>
Sent: Tuesday, July 16, 2019 1:32 AM
To: pgsql-general@lists.postgresql.org
Subject: Re: How to run a task continuously in the background
Creating a background worker that invokes a stored procedure once per
second? <https://www.postgresql.org/docs/11/bgworker.html<https://urldefense.proofpoint.com/v2/url?u=https...;
But this is not so simple to put in place.
It's not really important that the job runs once a second, but that it starts immediately when I want it to.
If I start a job with pg_cron, it will not be executed until the next full minute at the earliest.
Otherwise pg_cron with a function that performs a pg_sleep of one
second in a loop.
Anyway, it seems to me you are better refactoring your solution: it
seems you need to process data when _new data_ comes, not once per
second, so it sounds to me like a trigger could solve the problem.
The processing of the data via a job is deliberately chosen so as to separate the insertion of the data from their processing.
If a trigger were to do this, the transaction in which the data is inserted would take longer. This is not intended.
It is common for many records to be inserted in a short time, but processing takes a little time. The application that inserts the data should however not be slowed down.
Dirk
--
Dirk Mika
Software Developer
[cid:image001_d0a5cf51-5dd3-4ff5-b428-1016a6d95a0f.png]
mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany
fon +49 2202 2401-1197
dirk.mika@mikatiming.de
www.mikatiming.de
AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika
[cid:CCh2U_f27a5ce6-8556-4db1-8aa4-fd610d6e9efe.jpg]<https://urldefense.proofpoint.com/v2/url?u=https-3A__youtu.be_qfOFXrpSKLQ&d=DwMGaQ&c=EZxp_D7...;
Attachments:image001_d0a5cf51-5dd3-4ff5-b428-1016a6d95a0f.png (image/png, 1.7K) downloadview imageCCh2U_f27a5ce6-8556-4db1-8aa4-fd610d6e9efe.jpg (image/jpeg, 107.2K) downloadview image
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: gweatherby@uchc.edu
Subject: Re: How to run a task continuously in the background
In-Reply-To: <1563278313157.67005@uchc.edu>
References: <7932668C-EA48-436B-AA15-DB7C8446D57F@mikatiming.de> <E9FA92C2921F31408041863B74EE4C2001BD810545@CCPMAILDAG03.cantab.local> <CAOzAquKb+O3iu0pVBonDDSS8SH=a4Wa4hmYFxAbTwUCi7Hxjhg@mail.gmail.com> <D49B7AAD-5EC3-4D62-A263-E22E6633C807@mikatiming.de> <CAKoxK+7x4wEA-AMocZ00b8pAcBe2xZMq_6s8xsKPTWq7tGPdig@mail.gmail.com> <14555705-8010-4A73-8501-EA07B285E1BA@mikatiming.de> <1563278313157.67005@uchc.edu>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox