Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Nikolai Zhubr
Hi, 27.09.2015 23:22, Pavel Stehule wrote: [...] updated patch - fixed error reporting Wow! I'll definitely borrow it :) Thank you, Nikolai Regards Pavel -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org ) To make c

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Pavel Stehule
2015-09-27 22:51 GMT+02:00 Nikolai Zhubr : > Hi, > 27.09.2015 22:59, Pavel Stehule: > >> >> 2015-09-27 21:40 GMT+02:00 Jim Nasby > >: >> >> _PG_fini >> >> >> It should not work - see a doc >> > > I'd rather consider registering with on_shmem_exit -- as per the

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Pavel Stehule
Hi I stored this extension to github https://github.com/okbob/session_exec Regards Pavel

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Nikolai Zhubr
Hi, 27.09.2015 22:59, Pavel Stehule: 2015-09-27 21:40 GMT+02:00 Jim Nasby mailto:jim.na...@bluetreble.com>>: _PG_fini It should not work - see a doc I'd rather consider registering with on_shmem_exit -- as per the insightfull note placed in postgresql.c:4290. (Haven't tried - just thi

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Pavel Stehule
2015-09-27 13:33 GMT+02:00 Nikolai Zhubr : > Hi, > 27.09.2015 8:29, Pavel Stehule: > >> I'll check it. >> >> >> It is working. Patch attached >> > > Oh, brilliant! This is a _huge_ help actually! > > If I understand it correctly, any unhandled SQL-level exceptions will > essentially be ignored

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Pavel Stehule
2015-09-27 21:40 GMT+02:00 Jim Nasby : > _PG_fini It should not work - see a doc If the file includes a function named _PG_fini, that function will be called immediately before unloading the file. Likewise, the function receives no parameters and should return void. Note that _PG_fini will only

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Jim Nasby
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 se

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Pavel Stehule
2015-09-27 13:33 GMT+02:00 Nikolai Zhubr : > Hi, > 27.09.2015 8:29, Pavel Stehule: > >> I'll check it. >> >> >> It is working. Patch attached >> > > Oh, brilliant! This is a _huge_ help actually! > > If I understand it correctly, any unhandled SQL-level exceptions will > essentially be ignored

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-27 Thread Nikolai Zhubr
Hi, 27.09.2015 8:29, Pavel Stehule: I'll check it. It is working. Patch attached Oh, brilliant! This is a _huge_ help actually! If I understand it correctly, any unhandled SQL-level exceptions will essentially be ignored there, so that the session will continue regardless? And maybe i

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Pavel Stehule
> >> > years ago I tried it, if I remember well. I had a problems with SPI >> calls, >> > because some caches was not initialized. I am not sure, and I didn't >> test >> > last time. >> >> You'd have to start your own transaction if you wanted one, and any >> uncaught error would effectively be FAT

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Nikolai Zhubr
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 unreli

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread David G. Johnston
On Saturday, September 26, 2015, Tom Lane wrote: > Pavel Stehule > writes: > > 2015-09-26 19:53 GMT+02:00 Nikolai Zhubr >: > >> And the events of session start and session end would seem quite generic > >> and usefull anyway? > > > I don't know. I am pretty sceptical - from my experience this re

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Pavel Stehule
2015-09-26 20:29 GMT+02:00 Tom Lane : > Pavel Stehule writes: > > 2015-09-26 19:59 GMT+02:00 Tom Lane : > >> A session-start hook is already possible at the C-code level, using > >> session_preload_libraries. It wouldn't be hard to write an extension > >> that exposed that in some useful way to

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Tom Lane
Pavel Stehule writes: > 2015-09-26 19:59 GMT+02:00 Tom Lane : >> A session-start hook is already possible at the C-code level, using >> session_preload_libraries. It wouldn't be hard to write an extension >> that exposed that in some useful way to SQL code. > years ago I tried it, if I remember

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Pavel Stehule
2015-09-26 19:59 GMT+02:00 Tom Lane : > Pavel Stehule writes: > > 2015-09-26 19:53 GMT+02:00 Nikolai Zhubr : > >> And the events of session start and session end would seem quite generic > >> and usefull anyway? > > > I don't know. I am pretty sceptical - from my experience this request was > > r

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Tom Lane
Pavel Stehule writes: > 2015-09-26 19:53 GMT+02:00 Nikolai Zhubr : >> And the events of session start and session end would seem quite generic >> and usefull anyway? > I don't know. I am pretty sceptical - from my experience this request was > related to unhappy designed projects. A session-end

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Pavel Stehule
2015-09-26 19:53 GMT+02:00 Nikolai Zhubr : > Hi Pavel, > 26.09.2015 19:26, Pavel Stehule wrote: > [...] > >> This cannot be solved without patching PostgreSQL source code :( . There >> are not good hooks for custom extension. Patch is relative simple, but I >> cannot to publish it. >> > > Ok, I se

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Nikolai Zhubr
Hi Pavel, 26.09.2015 19:26, Pavel Stehule wrote: [...] This cannot be solved without patching PostgreSQL source code :( . There are not good hooks for custom extension. Patch is relative simple, but I cannot to publish it. Ok, I see. Creating such a patch might be not very hard actually. But li

Re: [GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Pavel Stehule
2015-09-26 18:17 GMT+02:00 Nikolai Zhubr : > Hi all, > > I'm trying to find a soultion to automatically execute something > (preferrably a function or at least some pure sql statements) at the > beginning and at the end of a user session. As an example, imagine just > storing of all login and logo

[GENERAL] Server-side hooks for user session start and session end

2015-09-26 Thread Nikolai Zhubr
Hi all, I'm trying to find a soultion to automatically execute something (preferrably a function or at least some pure sql statements) at the beginning and at the end of a user session. As an example, imagine just storing of all login and logout timestamps (though the real task is a bit more