1

I need to make a dump via pg_dump in php so i've got a function like this:

function fnDump()
{
    exec("/usr/local/bin/sudo -u pg_user /usr/local/bin/pg_dump mon_alarm > /usr/home/user/monitor_test/renew_db/mon_alarm.sql",$out);
    var_dump($out);
}

The problem is that mon_alarm.sql file is empty. But when i execute this command via command line everything works fine. What should i change to create a dump in php?

1 Answer 1

3

If you're running PHP under a standard webserver setup, that won't work because it will run under the context of the webserver user, so sudo won't let you change user context like that.

If this is a script you're going to have to adjust sudo to run only the pg_dump command as passwordless sudo permissions for the user, otherwise your sudo command will prompt for a password and ruin your automated process.

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

1 Comment

thanks! i thought that adding nopasswd permission for psql is enough.

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.