On Tue, Jun 23, 2015 at 7:41 AM, Sandro Santilli <strk@keybit.net> wrote:
> Empirically, I seem to be getting the _PG_init call for a module while
> the active memory context lifetime is that of the function call which
> first needed to load the shared object.
>
> Is this the case ? Documented anywhere ?
> Initializing memory meant to be alive for the whole lifetime of a backend
> in that function is a bit complex if that's confirmed.
If you want something that lasts for the lifetime of the backend, just do
MemoryContext oldctx = MemoryContextSwitchTo(TopMemoryContext);
...
MemoryContextSwitchTo(oldctx);
I'm not sure what context you should expect in _PG_init(), although
what you mention doesn't sound unreasonable. But generally if you
want a long-lived context you should establish that explicitly
yourself. We try to keep short-lived contexts active whenever
possible because that avoids long-term leaks.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company