Thread: BUG #2532: os.chdir call in plpython function doesn't work

BUG #2532: os.chdir call in plpython function doesn't work

From
"Tiziano Tissino"
Date:
The following bug has been logged online:

Bug reference:      2532
Logged by:          Tiziano Tissino
Email address:      t.tissino@itaca.coopsoc.it
PostgreSQL version: 8.1.4
Operating system:   Linux (Ubuntu Dapper)
Description:        os.chdir call in plpython function doesn't work
Details:

I have a function like the following one:
CREATE OR REPLACE FUNCTION public.test() RETURNS int4 AS $BODY$
from os import chdir
chdir('/tmp')
test=plpy.execute('SELECT int_field FROM table1;')[0]['int_field']
return test
$BODY$ LANGUAGE 'plpythonu' VOLATILE;

when calling it, I get an error like this one:
db=# select test(); WARNING:  plpython: in function test:
DETAIL:  plpy.SPIError: Unknown error in PLy_spi_execute_query
ERROR:  could not open relation 1663/16737/18906: No such file or directory
CONTEXT:  SQL statement "SELECT int_field FROM table1;"

The same function, without the row "chdir('/tmp')", works fine.

I just upgraded to 8.1.4; with previous db version (8.0), that function
worked fine as well.

Re: BUG #2532: os.chdir call in plpython function doesn't work

From
Tom Lane
Date:
"Tiziano Tissino" <t.tissino@itaca.coopsoc.it> writes:
> I have a function like the following one:
> CREATE OR REPLACE FUNCTION public.test() RETURNS int4 AS $BODY$
> from os import chdir
> chdir('/tmp')
> test=plpy.execute('SELECT int_field FROM table1;')[0]['int_field']
> return test
> $BODY$ LANGUAGE 'plpythonu' VOLATILE;

chdir is a great way to break your database.  Don't do it.

Other things to avoid in plpythonu functions include: rm -rf,
kill -9 the postmaster, etc ...

            regards, tom lane