PG_DUMP via shell_exec returns "no password supplied"

Asked

Viewed 974 times

0

I successfully execute the following command from the terminal:

pg_dump -d teste -h 127.0.0.1 -p 5432 -U postgres -w -f /home/william/pgsql/17032701.backup

However, when I execute the command by shell_exec of PHP, I have the following return:

pg_dump: [archiver (db)] connection to database "teste" failed: fe_sendauth: no password supplied

I need to create a routine where the user has the power to create the backup of the database through the system interface. However, the user does not have the password (and even if he had it would not be necessary to inform the same).

If on the line of command, I withdraw -w, in both executions (shell_exec and terminal) it is necessary to enter the password to proceed. But this is far from my ideal.

In my search for the solution, I tried to change the settings of the pg_hba.config, but without success.

Thank you in advance.

1 answer

1

The parameter -w deletes the password question, pg_dump expects you to have an environment variable called PGPASSWORD. Before running your script create a PGPASSWORD environment variable with the password.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.