pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Magnus Hagander <mha@sollentuna.net>
To: Jay Parker <jbparker@ualr.edu>
To: pgsql-sql@postgresql.org
Subject: Re: triggering an external action
Date: Tue, 17 May 2005 20:09:24 +0200
Message-ID: <6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se> (raw)

>I am trying to find the best way for a database trigger to signal a 
>client process to take an action.
>
>Specifically, I am working on the classic problem of creating and 
>modifying system accounts based on the updates to a "person registry" 
>database.
>
>The basic model I'm working with has triggers on my tables of interest 
>that stick a person's unique ID into a "todo queue" table whenever 
>modifications are made.  The queue is periodically polled by a script 
>which processes and deletes each "todo" record.  The polling 
>script goes 
>to sleep for gradually increasing periods of time whenever it 
>polls the 
>queue and finds it empty.
>
>What I want is a trigger on the "todo" table that will "kick" my 
>processing script to make it wake up and process the queue 
>immediately. 
>  In an Oracle environment, I think I could use a database pipe to 
>achieve more or less the behavior I'm looking for, but I can't find 
>anything that does what I want in pgsql at the database level.
>
>I could write a trigger in C or Perl or something that would do 
>something at the OS level, like send a signal, but when I go down that 
>path I start having to deal with unix issues like having to elevate to 
>root privs to send a signal to a process that isn't running as 
>the pgsql 
>user, etc.  It is doable but gets complex quickly.
>
>Is there anything I'm missing at the database level that would help me 
>process updates in realtime?  (And if not, which of the other mailing 
>lists would be the most appropriate place for me to discuss 
>the best way 
>to implement an OS-level solution?)

This sounds like a job for LISTEN/NOTIFY:
http://www.postgresql.org/docs/8.0/static/sql-listen.html
http://www.postgresql.org/docs/8.0/static/sql-notify.html


//Magnus



view thread (4+ messages)  latest in thread

Message-ID: <6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se>
Permalink:  ../6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se/
Also on:    postgresql.org/message-id/6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se

 · 

reply

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-sql@postgresql.org
  Cc: mha@sollentuna.net, jbparker@ualr.edu
  Subject: Re: triggering an external action
  In-Reply-To: <6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se>
  References: <6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se>

* 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