Is there a way to automagically execute a function at connect/disconnect?
I was thinking about the possibility to have some kind of automatic cleanup when the 
client disconnects.

I would like to:
- Register a session id at connect time. (INSERT into sessions(sessId, user, host, 
...) ...)
- Use the session id to mark some objects as "in use" (UPDATE tbl SET 
usedBy=<sessionid> WHERE...).
- Automatically update all rows with this session-id as "unused" when the client 
disconnects from the backend.

I can not trust the client to exit cleanly all the time, so the cleanup function must 
be executed by the backend when the connection is lost. The client could exit nicely 
or crash or have a power failure or whatever. I don't expect bad things to happen very 
often, but if/when they do i want to be sure that no rows are "in use".

Any ideas?

/Mattias


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to