LOADing functions

Started by Andrew Beckerover 11 years ago3 messagesgeneral
Jump to latest
#1Andrew Becker
acbecker@gmail.com

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.

Thanks,
Andy

psql 9.3.5 from Macports
on OS X 10.10

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Becker (#1)
Re: LOADing functions

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Andrew Becker (#1)
Re: LOADing functions

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

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general