How can I set PGPASSWORD automatically when i run a batch file for auto backup of my postgresql database in windows

I have create a batch file and write code as per picture. But my problem is it is always asked my pgpassword though i have already define it first. I need a solution early. TIA.

set PGPASSWORD=123456 
pg_dump -U postgres -W -F c YBD_ERP_Latest > E:\DBBackup\db_backup_%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2%.backup

enter image description here

Upvotes: 4

Views: 1203

Answers (1)

JGH
JGH

Reputation: 17906

The doc says:

-W
--password

Force psql to prompt for a password before connecting to a database [...].

So even though you have defined the password in PGPASSWORD, you have also forced psql to prompt for a password.

--> just remove the -W flag from pgdump options

Upvotes: 4

Related Questions