Q: Executing functions at connect/disconnect?

Поиск
Список
Период
Сортировка
От Mattias Kregert
Тема Q: Executing functions at connect/disconnect?
Дата
Msg-id 002a01c34177$ccf926e0$09000a0a@kregert.se
обсуждение исходный текст
Ответы Re: Q: Executing functions at connect/disconnect?  (Darko Prenosil <darko.prenosil@finteh.hr>)
Список pgsql-general
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
theconnection is lost. The client could exit nicely or crash or have a power failure or whatever. I don't expect bad
thingsto happen very often, but if/when they do i want to be sure that no rows are "in use". 

Any ideas?

/Mattias


В списке pgsql-general по дате отправления:

Предыдущее
От: "scott.marlowe"
Дата:
Сообщение: Re: ERROR: Relation "pg_user" does not exist
Следующее
От: "Bruno BAGUETTE"
Дата:
Сообщение: [REPOST] Problem for dumping a 6.5.2 database