我想在命令行中使用 pg_restore 恢复我的数据库 postgres,并且我想将用户的密码直接放在命令中,我尝试了这个命令但不起作用
pg_restore -h localhost -p 5432 -U postgres -W 123 -d my_db my_backup.backup
但显示以下消息
pg_restore: too many arguments on the command line (the first being "-d")
我想在命令行中使用 pg_restore 恢复我的数据库 postgres,并且我想将用户的密码直接放在命令中,我尝试了这个命令但不起作用
pg_restore -h localhost -p 5432 -U postgres -W 123 -d my_db my_backup.backup
但显示以下消息
pg_restore: too many arguments on the command line (the first being "-d")
将密码设置为环境变量:set "PGPASSWORD=123"
您也可以通过这种方式设置其他参数:https ://www.postgresql.org/docs/current/static/libpq-envars.html
-W是强制提示密码,而不是直接提供密码,这就是为什么它说参数太多。
把它们放在一起:
set "PGPASSWORD=123"
pg_restore -h localhost -p 5432 -U postgres -d my_db my_backup.backup
更新:感谢@aschipfl,我最初的引用不正确set