From: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> |
---|---|
To: | Bill Moran <wmoran(at)potentialtech(dot)com> |
Cc: | jacques klein <jacques(dot)klei(at)googlemail(dot)com>, David Fetter <david(at)fetter(dot)org>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: how to write/setup a C trigger function in a background worker |
Date: | 2015-08-19 21:17:55 |
Message-ID: | 20150819211755.GL5232@alvherre.pgsql |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Bill Moran wrote:
> On Wed, 19 Aug 2015 19:45:47 +0200
> jacques klein <jacques(dot)klei(at)googlemail(dot)com> wrote:
>
> > Well, sorry David, I don't understand what you mean,
> >
> > let me explain what I want to do: in short, IPC between "background
> > workers".
> >
> > I am trying to transform my app. from a multi-threaded C SQL-client into
> > some "background workers", execution speed beeing the goal (avoid
> > network io).
> > Worker start/stopping is nicely solved by server start/stop, but I have
> > also to do some messaging/notifying between my worker processes, and
> > would like to use a Postgres based solution instead of the usual unix or
> > network ipc, or course by avoiding polling (tables acting as message
> > queues).
>
> I think what David is saying, and what I would suggest, is the
> following:
>
> * It's not possible to have a trigger execute in the background
> * Create a background job that runs perpetually and listens for
> notification that it has work to do (i.e. it sleeps until notified)
> * Notify the job from the trigger
You could use shm_mq for IPC between backend (trigger) and bgworker, but
what should the backend do when the bgworker is not running for whatever
reason? One option is to curl up and die of course (i.e. abort the
transaction that fires the action). Also consider what happens if your
backend sends the notify and commits, and before the bgworker does its
stuff the system crashes. You will be happy to have things queued in a
database table ...
--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Janes | 2015-08-19 21:31:33 | Re: Mention column name in error messages |
Previous Message | Bill Moran | 2015-08-19 20:54:22 | Re: how to write/setup a C trigger function in a background worker |