On Fri, Nov 3, 2017 at 11:19 AM, Michael Paquier <
michael.paquier@gmail.com> wrote:
>
> /*
> + * Setup handler to session end hook
> + */
> + if (IsUnderPostmaster)
> + on_proc_exit(do_session_end_hook, 0);
> I think that it would be better to place that in ShutdownPostgres.
> This way it is possible to take actions before any resource is shut
> down.
>
Hmmm... ok but I have some doubt... ShutdownPostgres make sure to abort any active transaction (AbortOutOfAnyTransaction) and release all locks (LockReleaseAll). If we hook session end at this point we'll do that after this two steps and after that run again... something like:
...
/* Make sure we've killed any active transaction */
AbortOutOfAnyTransaction();
/*
* User locks are not released by transaction end, so be sure to release
* them explicitly.
*/
LockReleaseAll(USER_LOCKMETHOD, true);
if (session_end_hook) {
(*session_end_hook) (port->database_name, port->user_name);
/* Make sure session end hook doesn't leave trash behind */
AbortOutOfAnyTransaction();
LockReleaseAll(USER_LOCKMETHOD, true);
}
...