Thread: LOADing functions

LOADing functions

From
Andrew Becker
Date:
Hi - I seem to be unable to reLOAD a shared library within the session that I LOADed it.  I am developing a UDF and my debugging changes do not appear to take until I quit psql and restart.  The following code sequence demonstrates the issue

kbmod=#  CREATE OR REPLACE FUNCTION hello(TEXT) RETURNS TEXT    AS '/Users/acbecker/src/github/kbmod/src/hello.so', 'hello'    LANGUAGE C STRICT;

kbmod=# SELECT hello( name ) FROM test;    hello      
----------------Hello4, XavierHello4, YariHello4, Zack
(3 rows)


### HERE I MODIFY hello.c TO TYPE "Hello5" AND REBUILD hello.so


### DROPPING AND RECREATING THE FUNCTION DOES NOT WORK

kbmod=# DROP FUNCTION hello(TEXT);

kbmod=#  CREATE OR REPLACE FUNCTION hello(TEXT) RETURNS TEXT    AS '/Users/acbecker/src/github/kbmod/src/hello.so', 'hello'    LANGUAGE C STRICT;

kbmod=# SELECT hello( name ) FROM test;   hello     
---------------Hello4, XavierHello4, YariHello4, Zack


### RELOADING THE SHARED LIBRARY ALSO DOES NOT HELP
kbmod=# LOAD '/Users/acbecker/src/github/kbmod/src/hello.so';
LOAD

kbmod=# SELECT hello( name ) FROM test;    hello      
----------------Hello4, XavierHello4, YariHello4, Zack
(3 rows)

### HOWEVER, AFTER QUITTING AND RESTARTING, THE CHANGE TAKES

kbmod=# \q

prompt>:/opt/local/lib/postgresql93/bin/psql -U postgres -d kbmod

psql (9.3.5)
Type "help" for help.

kbmod=# SELECT hello( name ) FROM test;    hello      
----------------Hello5, XavierHello5, YariHello5, Zack
(3 rows)


Hints as to what is going wrong here?  I would certainly expect to be able to re-load a shared library while debugging my UDF.

Thanks,
Andy

psql 9.3.5 from Macports
on OS X 10.10

Re: LOADing functions

From
Tom Lane
Date:
Andrew Becker <acbecker@gmail.com> writes:
> Hi - I seem to be unable to reLOAD a shared library within the session
> that I LOADed it.

Nope, you can't, there's no such functionality.

> Hints as to what is going wrong here?  I would certainly expect to be
> able to re-load a shared library while debugging my UDF.

That would require being able to unload it, which is an operation fraught
with hazards.  We used to allow that, but gave it up after observing that
practically every extant extension could be made to crash on unload.
There is for instance no safe way to get out of a function hook --- the
code pattern you may have seen of restoring the prior value is wrong and
unsafe, because it doesn't account for some other extension having plugged
into the hook after you.  You'd leave that other extension kneecapped,
with some of its hook callbacks disabled but others perhaps not.

            regards, tom lane


Re: LOADing functions

From
Adrian Klaver
Date:
On 10/31/2014 03:00 PM, Andrew Becker wrote:
> Hi - I seem to be unable to reLOAD a shared library within the session
> that I LOADed it.  I am developing a UDF and my debugging changes do not
> appear to take until I quit psql and restart.  The following code
> sequence demonstrates the issue
>
> |kbmod=#  CREATE OR REPLACE FUNCTION hello(TEXT) RETURNS TEXT
>       AS '/Users/acbecker/src/github/kbmod/src/hello.so', 'hello'
>       LANGUAGE C STRICT;
>
> ||kbmod=# SELECT hello( name ) FROM test;
>       hello
> ----------------
>   Hello4, Xavier
>   Hello4, Yari
>   Hello4, Zack
> (3 rows)
>
>
> ### HERE I MODIFY hello.c TO TYPE "Hello5" AND REBUILD hello.so
> |
>
> |### DROPPING AND RECREATING THE FUNCTION DOES NOT WORK
>
> kbmod=# DROP FUNCTION hello(TEXT);
>
> kbmod=#  CREATE OR REPLACE FUNCTION hello(TEXT) RETURNS TEXT
>       AS '/Users/acbecker/src/github/kbmod/src/hello.so', 'hello'
>       LANGUAGE C STRICT;
>
> kbmod=# SELECT hello( name ) FROM test;
>      hello
> ---------------
>   Hello4, Xavier
>   Hello4, Yari
>   Hello4, Zack
>
>
> ### RELOADING THE SHARED LIBRARY ALSO DOES NOT HELP
> |
>
> |kbmod=# LOAD '/Users/acbecker/src/github/kbmod/src/hello.so';
> LOAD
>
> kbmod=# SELECT hello( name ) FROM test;
>       hello
> ----------------
>   Hello4, Xavier
>   Hello4, Yari
>   Hello4, Zack
> (3 rows)
> |
> ### HOWEVER, AFTER QUITTING AND RESTARTING, THE CHANGE TAKES
>
> |kbmod=# \q
>
> prompt>:/opt/local/lib/postgresql93/bin/psql -U postgres -d kbmod
>
> psql (9.3.5)
> Type "help" for help.
>
> kbmod=# SELECT hello( name ) FROM test;
>       hello
> ----------------
>   Hello5, Xavier
>   Hello5, Yari
>   Hello5, Zack
> (3 rows)|
>
>
>
> Hints as to what is going wrong here?  I would certainly expect to be
> able to re-load a shared library while debugging my UDF.

The docs would say otherwise:

http://www.postgresql.org/docs/9.3/interactive/sql-load.html

This command loads a shared library file into the PostgreSQL server's
address space. If the file has been loaded already, the command does
nothing.



>
> Thanks,
> Andy
>
> psql 9.3.5 from Macports
> on OS X 10.10


--
Adrian Klaver
adrian.klaver@aklaver.com