10

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")
Fares Izem
  • 177
  • 2
  • 2
  • 9

1 Answers1

18

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

mike.k
  • 3,277
  • 1
  • 12
  • 18