Обсуждение: Regarding shared_preload_libraries (postgresql.conf file)

Поиск
Список
Период
Сортировка

Regarding shared_preload_libraries (postgresql.conf file)

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


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

 But if we do not pre-load shared library(removing entry from shared_preload_libraries in .conf file), everything works fine (We were able to open badger db, put, get etc.. from any process)
 
 As we are not aware of how postgres loads and manages its shared library things, we couldn't figure out the issue exactly. Your suggestions are valuable.

Thanks & Regards,
Abinaya KR

Re: Regarding shared_preload_libraries (postgresql.conf file)

От
David Fetter
Дата:
On Thu, Jul 05, 2018 at 06:46:26PM +0530, Abi KR wrote:
> hello everyone,
>      We wanted to make use of embedded key-value store(BadgerDB -
> implemented in golang) to save the data related to our extension.
> 
> 
> The problem is,
>     when we load our extension using shared_preload_libraries, we could
> able to open badgerdb and use it in postmaster process(_pg_init) only but
> not in any other background processes.
> 
> 
>  But if we do not pre-load shared library(removing entry from
> shared_preload_libraries in .conf file), everything works fine (We were
> able to open badger db, put, get etc.. from any process)
> 
>  As we are not aware of how postgres loads and manages its shared library
> things, we couldn't figure out the issue exactly. Your suggestions are
> valuable.
> 
> Thanks & Regards,
> Abinaya KR

What precisely are you trying to do here, and how are you doing it?
Is the source published somewhere?

Best,
David.
-- 
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


Re: Regarding shared_preload_libraries (postgresql.conf file)

От
Andrew Gierth
Дата:
>>>>> "Abi" == Abi KR <abi.kr.2016@gmail.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)