Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B19F3172C063 for ; Sun, 4 Dec 2011 17:56:34 -0400 (AST) Received: from [2001:1528:137::f1] (helo=mail.gransy.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RXK2z-0006Mj-IO for pgsql-hackers@postgresql.org; Sun, 04 Dec 2011 21:56:34 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id C41734A209E for ; Sun, 4 Dec 2011 22:56:20 +0100 (CET) Received: from mail.gransy.com ([82.208.29.194]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id MqqCymlaNJjU for ; Sun, 4 Dec 2011 22:56:20 +0100 (CET) Received: from [192.168.1.237] (ip-78-45-133-255.net.upcbroadband.cz [78.45.133.255]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 800A34A2095 for ; Sun, 4 Dec 2011 22:56:20 +0100 (CET) Message-ID: <4EDBEC84.2030809@fuzzy.cz> Date: Sun, 04 Dec 2011 22:56:20 +0100 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: why local_preload_libraries does require a separate directory ? References: <4EDA38AE.5030003@fuzzy.cz> <17337.1322934799@sss.pgh.pa.us> <4EDA6C0E.6090909@fuzzy.cz> <17796.1323033362@sss.pgh.pa.us> In-Reply-To: <17796.1323033362@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:1528:137::f1 (failed) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201112/169 X-Sequence-Number: 199421 On 4.12.2011 22:16, Tom Lane wrote: > Tomas Vondra 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