Re: Postgresql init and cleanup module functions

From: Yan Pas <yanp(dot)bugz(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Postgresql init and cleanup module functions
Date: 2017-09-06 11:55:20
Message-ID: CADceNN6VbSCPTbp1gFp2pyOT2Dr-j2Y76TAWKn6rQWjO5jFvtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sorry, replied only to direct sender, duplicating to both sender and
mailing list
*---*
*MSG1:*
Thanks you, that is what I was looking for!

I was testing sample module and found it's behavior odd:
1. functions have few permissions, they even were not able to create file
in "/tmp" directory. At least I'm able to use pglog (ereport(LOG,
(errmsg("init")));)
2. _PG_init() is called separately for each connection right before any of
the module's function is called by the client, so there are many instances
of the module
3. For cleaning up I've use trick with standard 'atexit' function, called
inside _PG_init() and it works properly
4. Global object's constructor and destructor are called on module unload.

I thought it works like "dlopen on postgres start, dlclose on postgres
shutdown". I think I should stick to background worker process which will
provide some C-Postgres functions
*---*
*MSG2:*
After reading bg workers' manual it seems to me that they cannot provide
postgres functions. So the only way to achieve ONE global state and
postgres functions using this state is to use some IPC between background
process and dynamicaly loadable module (e.g. Unix/TCP sockets)

Regards, Yan

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2017-09-06 12:35:35 Re: Dealing with number formats when server and client are different locales
Previous Message Vick Khera 2017-09-06 11:09:59 Re: Postgres logs showing error after replication