Postgresql:使用密码编写 psql 执行脚本 [英] Postgresql: Scripting psql execution with password
本文介绍了Postgresql:使用密码编写 psql 执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何调用 psql 使其不提示输入密码?
这就是我所拥有的:
psql -Umyuser < myscript.sql
然而,我找不到传递密码的参数,所以 psql 总是提示它.
However, I couldn't find the argument that passes the password, and so psql always prompts for it.
推荐答案
您可能希望阅读 向 PostgreSQL 进行身份验证的方法.
为了回答您的问题,有几种方法可以为基于密码的身份验证提供密码:
To answer your question, there are several ways provide a password for password-based authentication:
通过密码提示.示例:
psql -h uta.biocommons.org -U foo
Password for user foo:
在 pgpass 文件中.请参阅 libpq-pgpass.格式:
<host>:<port>:<database>:<user>:<password>
使用 PGPASSWORD
环境变量.请参阅 libpq-envars.示例:
export PGPASSWORD=yourpass
psql ...
# Or in one line for this invocation only:
PGPASSWORD=yourpass psql ...
在连接字符串中 可以在连接字符串/URI 中指定密码和其他选项.请参阅 app-psql.示例:
In the connection string The password and other options may be specified in the connection string/URI. See app-psql. Example:
psql postgresql://username:password@dbmaster:5433/mydb?sslmode=require
这篇关于Postgresql:使用密码编写 psql 执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文