pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tv@fuzzy.cz>
To: pgsql-hackers@postgresql.org
Subject: Re: why local_preload_libraries does require a separate directory ?
Date: Sun, 04 Dec 2011 22:56:20 +0100
Message-ID: <4EDBEC84.2030809@fuzzy.cz> (raw)
In-Reply-To: <17796.1323033362@sss.pgh.pa.us>
References: <4EDA38AE.5030003@fuzzy.cz>
	<17337.1322934799@sss.pgh.pa.us>
	<4EDA6C0E.6090909@fuzzy.cz>
	<17796.1323033362@sss.pgh.pa.us>

On 4.12.2011 22:16, Tom Lane wrote:
> Tomas Vondra <tv@fuzzy.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
   shared_preload_libraries)

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.

Tomas



view thread (8+ messages)  latest in thread

Message-ID: <4EDBEC84.2030809@fuzzy.cz>
Permalink:  ../4EDBEC84.2030809@fuzzy.cz/
Also on:    postgresql.org/message-id/4EDBEC84.2030809@fuzzy.cz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tv@fuzzy.cz
  Subject: Re: why local_preload_libraries does require a separate directory ?
  In-Reply-To: <4EDBEC84.2030809@fuzzy.cz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox