X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1B8285282F for ; Tue, 17 May 2005 15:09:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 67969-01 for ; Tue, 17 May 2005 18:09:27 +0000 (GMT) Received: from mx-2.sollentuna.net (mx-2.sollentuna.net [195.84.163.199]) by svr1.postgresql.org (Postfix) with ESMTP id B226952804 for ; Tue, 17 May 2005 15:09:24 -0300 (ADT) Received: from ALGOL.sollentuna.se (janus.sollentuna.se [62.65.68.67]) by mx-2.sollentuna.net (Postfix) with ESMTP id 9D1528F283; Tue, 17 May 2005 20:09:24 +0200 (CEST) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Subject: Re: triggering an external action Date: Tue, 17 May 2005 20:09:24 +0200 Message-ID: <6BCB9D8A16AC4241919521715F4D8BCE6C74E2@algol.sollentuna.se> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [SQL] triggering an external action Thread-Index: AcVbCwLBY/ZC3f9PSO+4J5uBYf76VAAAGUMA From: "Magnus Hagander" To: "Jay Parker" , X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.065 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200505/134 X-Sequence-Number: 21447 >I am trying to find the best way for a database trigger to signal a=20 >client process to take an action. > >Specifically, I am working on the classic problem of creating and=20 >modifying system accounts based on the updates to a "person registry"=20 >database. > >The basic model I'm working with has triggers on my tables of interest=20 >that stick a person's unique ID into a "todo queue" table whenever=20 >modifications are made. The queue is periodically polled by a script=20 >which processes and deletes each "todo" record. The polling=20 >script goes=20 >to sleep for gradually increasing periods of time whenever it=20 >polls the=20 >queue and finds it empty. > >What I want is a trigger on the "todo" table that will "kick" my=20 >processing script to make it wake up and process the queue=20 >immediately.=20 > In an Oracle environment, I think I could use a database pipe to=20 >achieve more or less the behavior I'm looking for, but I can't find=20 >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=20 >something at the OS level, like send a signal, but when I go down that=20 >path I start having to deal with unix issues like having to elevate to=20 >root privs to send a signal to a process that isn't running as=20 >the pgsql=20 >user, etc. It is doable but gets complex quickly. > >Is there anything I'm missing at the database level that would help me=20 >process updates in realtime? (And if not, which of the other mailing=20 >lists would be the most appropriate place for me to discuss=20 >the best way=20 >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