From: | Luca Ferrari <fluca1978(at)gmail(dot)com> |
---|---|
To: | Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de> |
Cc: | "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: How to run a task continuously in the background |
Date: | 2019-07-17 09:02:42 |
Message-ID: | CAKoxK+4XysF-aA3VvFMn6pQYXsgs1o92JZ5uGx8=18Fr8+q4xA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Jul 17, 2019 at 9:38 AM Dirk Mika <Dirk(dot)Mika(at)mikatiming(dot)de> wrote:
> That is basically still my main question. How do I start a background job (e.g. a function) which waits by polling or LISTEN / NOTIFY for records in a table to be processed.
You will have a trigger that, once new tuples are created (or older
update and so on) issues a NOTIFY.
Somewhere (within PostgreSQL or outside it) there will be a process
that issued a LISTEN and is locked until a notify comes in. Then it
does process whatever you need to do.
As an example your trigger function will be something like
<https://github.com/fluca1978/PostgreSQL-11-Quick-Start-Guide/blob/master/Chapter09/Chapter09_Listing05.sql>
and your listening process will be something like
<https://github.com/fluca1978/PostgreSQL-11-Quick-Start-Guide/blob/master/Chapter09/Chapter09_Listing09.perl>.
This makes your processing fully asynchronous, and with some tune
allows you to decide the start/stop/resume policy as you need/wish.
Besides, it is quite hard for me to get to the point where you need to
check for new data every second, and therefore why you are not
satisfied with pg_cron or stuff like that.
Luca
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2019-07-17 09:13:38 | Re: Issue related with patitioned table:How can I quickly determine which child table my record is in,given a specific primary key value? |
Previous Message | Rob Sargent | 2019-07-17 07:45:02 | Re: How to run a task continuously in the background |