Skip site navigation (1) Skip section navigation (2)

Re: why local_preload_libraries does require a separate directory ?

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: why local_preload_libraries does require a separate directory ?
Date: 2011-12-04 21:56:20
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On 4.12.2011 22:16, Tom Lane wrote:
> Tomas Vondra <tv(at)fuzzy(dot)cz> writes:
>> On 3.12.2011 18:53, Tom Lane wrote:
>>> Security: it lets the DBA constrain which libraries are loadable this way.
>> But local_preload_libraries can be set only in postgresql.conf, right?
> No.  It's PGC_BACKEND, which means it can be set at connection start by
> a client (eg, via PGOPTIONS).
>> The problem I'm trying to solve right now is that I do have an extension
>> that needs to install two .so libraries - one loaded using
>> shared_preload_libraries, one loaded using local_preload_libraries.
> Um ... why would you design it like that?

Well, the purpose of the extension is to limit number of connections by
db/user/IP. It's using pg_stat_activity and auth hook, and the rules are
loaded from a file into a shared memory segment.

So I need to:

1) allocate memory to keep the rules (so it has to be loaded using

2) check the rules (this is done in auth hook) using pg_stat_activity

The backends are added to pg_stat_activity after the auth hook finishes,
which means possible race conditions (backends executed at about the
same time don't see each other in pg_stat_activity). So I use an
exclusive lock that's acquired before reading pg_stat_activity and
released after the pg_stat_activity is updated.

That's the only thing the library loaded using local_preload_libraries
does - it releases the lock.


In response to


pgsql-hackers by date

Next:From: Martin PihlakDate: 2011-12-04 22:10:03
Subject: Re: logging in high performance systems.
Previous:From: Pavel StehuleDate: 2011-12-04 21:51:29
Subject: Re: planner fails on HEAD

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group