PG_DUMP via shell_exec returns "no password supplied"

0

I successfully execute the following command through 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 get 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 can create the backup of the database through the system interface. However, the user does not have the password (and even if it had, it would not be necessary to inform the password).

If on the command line, I remove -w , in both runs ( 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 pg_hba.config , but without success.

Thank you in advance.

    
asked by anonymous 27.03.2017 / 03:30

1 answer

1

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

    
29.03.2017 / 22:31