Re: Regarding shared_preload_libraries (postgresql.conf file)

From: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
To: Abi KR <abi(dot)kr(dot)2016(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Regarding shared_preload_libraries (postgresql.conf file)
Date: 2018-07-05 16:40:14
Message-ID: 87601tmynf.fsf@news-spur.riddles.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>>>> "Abi" == Abi KR <abi(dot)kr(dot)2016(at)gmail(dot)com> writes:

Abi> hello everyone,
Abi> We wanted to make use of embedded key-value store(BadgerDB -
Abi> implemented in golang) to save the data related to our extension.

Abi> The problem is, when we load our extension using
Abi> shared_preload_libraries, we could able to open badgerdb and use
Abi> it in postmaster process(_pg_init) only but not in any other
Abi> background processes.

You have to be very careful about doing things in a preloaded module's
_PG_init that might not be inherited properly over a fork().

In particular, if you open files then the descriptors (with their seek
positions) will be shared between all the backend processes, which will
likely cause chaos. Likewise, connections to remote services will end up
being shared with similar results.

In short, you shouldn't do anything inside _PG_init that isn't
completely self-contained within the current process. Anything more
involved, such as opening external databases, should be done on the
first call to an actual function. If in doubt, do nothing inside
_PG_init except for setup of custom GUC variables.

--
Andrew (irc:RhodiumToad)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2018-07-05 16:58:27 Re: Make deparsing of column defaults faster
Previous Message Alvaro Herrera 2018-07-05 16:35:29 Re: Non-reserved replication slots and slot advancing