Re: [GENERAL] Postgresql init and cleanup module functions - Mailing list pgsql-general

From Yan Pas
Subject Re: [GENERAL] Postgresql init and cleanup module functions
Date
Msg-id CADceNN6VbSCPTbp1gFp2pyOT2Dr-j2Y76TAWKn6rQWjO5jFvtA@mail.gmail.com
Whole thread Raw
In response to Re: [GENERAL] Postgresql init and cleanup module functions  (Andres Freund <andres@anarazel.de>)
List 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

pgsql-general by date:

Previous
From: Vick Khera
Date:
Subject: Re: [GENERAL] Postgres logs showing error after replication
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] Dealing with number formats when server and client are different locales