From: | Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com> |
---|---|
To: | Nikolai Zhubr <n-a-zhubr(at)yandex(dot)ru>, PG-General Mailing List <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Server-side hooks for user session start and session end |
Date: | 2015-09-27 19:40:24 |
Message-ID: | 56084628.5080205@BlueTreble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 9/26/15 7:12 PM, Nikolai Zhubr wrote:
> 26.09.2015 20:59, Tom Lane wrote:
> [...]
>> A session-end hook seems pretty problematic to me: you simply cannot
>> guarantee that it will run at all. (Consider process crash or server
>> abort cases.) So anything built on the assumption that it gets to run
>> at session end is going to be inherently unreliable.
>
> Yes, I understand that.
> For such cases (of e.g. abnormal shutdown) it would also be nice if a
> database could 'autorun' some specified function just after server has
> performed whetever startup/replay/cleanup procedures necessary and
> immediately before it is ready for normal operation. This would allow to
> perform some checks and cleanups to restore consistency. And actually,
> such 'autorun' function could be interesting regardless of this session
> begin/end thing.
> And there are already quite some hooks in use for session-end cleanups
> at C-level, like e.g. for disposing temp tables, just none of them
> expose anything to SQL level. I'd guess this technique is available for
> use by extensions, so potentially SQL-level hook could also be
> implemented. Though I think it is a bit beyond my capability at the
> moment...
Actually, there's probably some other hooks you could use for this purpose.
BTW, if you want to extend Pavel's code to also handle logout, you just
need to create a _PG_fini function. See the end of this section in the
docs: http://www.postgresql.org/docs/9.4/static/xfunc-c.html#XFUNC-C-DYNLOAD
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2015-09-27 19:59:39 | Re: Server-side hooks for user session start and session end |
Previous Message | Jim Nasby | 2015-09-27 19:31:35 | Re: error on CREATE INDEX when restoring from dump file: could not read block 0 |