【问题标题】:put automatically password of user in pg_restore command line windows [duplicate]在pg_restore命令行窗口中自动输入用户密码[重复]
【发布时间】:2018-11-30 23:33:58
【问题描述】:

我想在命令行中使用 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")

【问题讨论】:

    标签: postgresql cmd postgresql-9.5


    【解决方案1】:

    设置密码为环境变量: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 的引用不正确

    【讨论】:

    • 问题没有问到,但是使用密码文件更安全。
    • 使用set PGPASSWORD="123"时,引号是变量值的一部分;写set "PGPASSWORD=123" 来避免这种情况......
    猜你喜欢
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多