Trigger to run @ connection time? - Mailing list pgsql-general

From Kynn Jones
Subject Trigger to run @ connection time?
Date
Msg-id c2350ba40803101307u238dd124t29e0c9e52d221cbf@mail.gmail.com
Whole thread Raw
Responses Re: Trigger to run @ connection time?  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: Trigger to run @ connection time?  ("Greg Sabino Mullane" <greg@turnstep.com>)
List 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

pgsql-general by date:

Previous
From: frant101@googlemail.com
Date:
Subject: Reindexdb + relation error
Next
From: John Cartwright
Date:
Subject: php pg_connect fails, pgsql works