Trigger to run @ connection time?

From: "Kynn Jones" <kynnjo(at)gmail(dot)com>
To: "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: Trigger to run @ connection time?
Date: 2008-03-10 20:07:41
Message-ID: c2350ba40803101307u238dd124t29e0c9e52d221cbf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi! I want to set up a trigger (somehow) that, whenever someone connects
database my_db, will fire and thereby run a stored PLPERL procedure
perl_setup() in the new connection's environment. (BTW, this procedure adds
useful definitions, mostly subs, to Perl's main package. This needs to be
done for each connection, because such modifications of package main do not
persist from one session to the next.)

I figured that setting up such a trigger would be possible, based on the
naive assumption that all global events of interest (e.g. the opening (or
closing) of a connection to a specific database, or the creation of a new
database) would correspond to an INSERT, UPDATE, or DELETE event on some
system table.

So I tried to find some system table that would get modified whenever a new
connection was made, but I was unsuccessful. The closest I found was the
VIEW pg_activity, and the crucial information I need from this view comes
from procedures like pg_stat_get_backend_pid().

Is there a bona fide table (not a view!) that I could use to define an "on
connect" trigger? (This table would not only have to undergo some INSERT or
UPDATE event at the time of the new connection, but it should also provide
enough information to allow my code to determine which database is being
connected to.)

If not, is there some other way to set up a trigger that

TIA!

Kynn

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Cartwright 2008-03-10 20:14:03 php pg_connect fails, pgsql works
Previous Message Harald Fuchs 2008-03-10 19:03:03 Re: ISO something like "#if 0 ... #endif" for SQL code