Re: writing & flushing C extensions - Mailing list pgsql-general

From Tom Lane
Subject Re: writing & flushing C extensions
Date
Msg-id 14341.1003158130@sss.pgh.pa.us
Whole thread Raw
In response to writing & flushing C extensions  ("John P. Looney" <john@antefacto.com>)
List pgsql-general
"John P. Looney" <john@antefacto.com> writes:
>  I'm trying to write a few functions in C for postgres. But, when I change
> some code, I'm never sure that it'll be flushed when I do a;

>  DROP FUNCTION test();
>  CREATE FUNCTION test() RETURNS text AS '/var/lib/pgsql/functions/test.so' LANGUAGE 'c';

Actually, you can be pretty sure that it *won't* be flushed; once a
backend has loaded a dynamic link library, the library stays loaded
till the backend exits.  Dropping/recreating individual function
definitions that point at the library makes no difference.

I believe the only way to get an updated copy of a library without
starting a new backend is to execute the LOAD command, which will
unload and reload the library.

>  Is there a way to make sure ? Even restarting postgres doesn't always
> work (or else my makefiles are broken...)

Better take a hard look at your makefiles then... a fresh backend
definitely will load the current copy of the .so file on first reference
to any function in it.

You didn't say what platform you are on, but on some platforms it's
not allowed to delete or overwrite a shared library file that is
currently open for execution.  If yours is like this then the makefile's
attempt to install the new .so might be failing.  Best solution that
I know of is to move the old .so out of the way, install the new,
then attempt to delete the old.

            regards, tom lane

pgsql-general by date:

Previous
From: Chris Cameron
Date:
Subject: Managing Users
Next
From: speedboy
Date:
Subject: Re: WWW interface for postgres