Re: Feedback on writing extensible modules

From: Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndQuadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Feedback on writing extensible modules
Date: 2009-07-05 22:02:49
Message-ID: 2EC50AA5-464B-4248-A2BF-FFBC3A249D42@hi-media.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Le 31 mai 09 à 18:21, Tom Lane a écrit :
> The reason this doesn't work is that SPI can only be invoked inside a
> transaction, and you're not inside one when a library is being
> preloaded.

Please find attached a little little patch which run
process_local_preload_libraries from within a transaction.

The following patch to preprepare makes it working fine when the GUC
preprepare.at_init is on and the module is being loaded from
local_preload_librairies:
http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/preprepare/preprepare/pre_prepare.c.diff?r1=1.1&r2=1.2

> You could maybe make this work by executing your own transaction
> to do it

I took the option to have PostgreSQL provide the same context in
preloading that when loading later, in that in both case _PG_init()
runs inside an already existing transaction. I don't see a current way
for _PG_init() to distinguish between being called at backend fork()
time or from a user transaction, so figured it was better this way.

> but I really have to wonder if it's a good idea. One
> point to think about is that elog(ERROR) still means elog(FATAL)
> at this point, so any brokenness in the queries you're trying to
> prepare will result in locking all users out of the database.

Well loading custom code at init time is a foot-gun reserved to
superusers with access to the local file system (where to put the
custom .so) and allowed to signal postmaster. You're right that a
failure in the module init routine will prevent anyone from connecting
to the server, but the cure is to clean local_preload_librairies then
restart.
Or with the preprepare example, to set preprepare.at_init to off then
reload.

Regards,
--
dim

Attachment Content-Type Size
preload-spi.diff application/octet-stream 675 bytes
unknown_filename text/plain 245 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-07-05 22:24:58 Re: Feedback on writing extensible modules
Previous Message Robert Haas 2009-07-05 21:34:49 Re: Merge Append Patch merged up to 85devel