0

As a preliminary test for a further work I'm trying to use a simple plpythonu function in Postgresql 9.2 to create a folder in my filesystem. So I have this code :

CREATE OR REPLACE FUNCTION "mkdir_test"() 
RETURNS void AS $BODY$ 

import os

dir = os.path.dirname('/tmp/areas/testdir/')
if not os.path.exists(dir):
    os.makedirs(dir)


$BODY$

LANGUAGE plpythonu
COST 100
CALLED ON NULL INPUT
SECURITY INVOKER
VOLATILE;
ALTER FUNCTION "mkdir_test"() OWNER TO "chewbacca";

It works, but then the directory created 'testdir' belongs to _postgres and has privileges '700', meaning that it is forbidden to anyone but postgres. How can I change this so that the user triggering this function is the owner of the file/folder created ? (Currently I'm doing this on Mac os x 10.11 but the objective is to have this working on any OS.)

  • run the 'chown' command, and perhaps the 'chmod' command? – Max Vernon Oct 23 '15 at 17:42
  • Thanks for answering. I don't get it : os.chmod(dir, 0777) is ok but not os.chown(dir, 501, -1), which produces an "operation not permitted". I'm trying to go further this way but I wish to find something where the user doing the operation would be the one connected to postgresql. – dd_a Oct 25 '15 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.