Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

put automatically password of user in pg_restore command line windows [duplicate]

I want to restore my database postgres using pg_restore in command line and i want to put the password of user directly in the command, I tried this command but doesn't work

pg_restore -h localhost -p 5432 -U postgres -W 123 -d my_db my_backup.backup

but the following message is displayed

pg_restore: too many arguments on the command line (the first being "-d")
like image 729
Fares Izem Avatar asked Jun 21 '18 15:06

Fares Izem


1 Answers

Set the password as an environment variable: set "PGPASSWORD=123" You can set other arguments this way as well: https://www.postgresql.org/docs/current/static/libpq-envars.html

-W is to force a password prompt, not to supply a password directly, thats why it says there are too many arguments.

Putting it all together:

set "PGPASSWORD=123"
pg_restore -h localhost -p 5432 -U postgres -d my_db my_backup.backup

Update: Thanks @aschipfl, I initially had incorrect quoting on set

like image 99
mike.k Avatar answered Nov 18 '22 01:11

mike.k