0

I am creating a procedure using plpgsql which calls a .bat file. This same .bat file manipulates files and directories (includes mkdir, rmdir...) but these commands are not being executed. I was reading that plpgsql is only for data manipulation -- so I am presuming this is the issue.

How can I work around this problem? Can I set some parameter to remove this restriction, use a new language, or what?

1 Answer 1

1

You should write the function in an untrusted language, e.g. PL/PythonU.

For the documentation::

Trusted languages are designed for ordinary database users (those without superuser privilege) and allows them to safely create functions and trigger procedures. Since PL functions are executed inside the database server, the TRUSTED flag should only be given for languages that do not allow access to database server internals or the file system. The languages PL/pgSQL, PL/Tcl, and PL/Perl are considered trusted; the languages PL/TclU, PL/PerlU, and PL/PythonU are designed to provide unlimited functionality and should not be marked trusted.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, interesting perspective... however since I am calling a .bat file, does your answer still apply? The 'security' aspects fall under the hands of this script - not plpgsql?
It's impossible to directly access a file system in a plpgsql function, you cannot run a bat file from it. You need an untrusted language.
@klin: When OP posted this question 3 hours earlier, they mentioned that they're firing it off via COPY FROM <program>.
@NickBarnes - I see, thanks. @Zenuno - the commands in the bat file are executed by an o.s. user who owns Postgres, typically it is user postgres (if you did not change it during installation). The user by default has limited access to file system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.