PostgreSQL命令行psql如何带上密码?

PostgreSQL命令行psql如何带上密码?


发布日期: 2023-08-13 更新日期: 2023-08-13 编辑:bukun 浏览次数: 1058

标签:

摘要: 可以参考stackoverflow里这个回答: postgresql-scripting-psql-execution-with-password 里面写道: "The obvious way is via the password prompt Inste...

可以参考stackoverflow里这个回答: postgresql-scripting-psql-execution-with-password

里面写道:

"The obvious way is via the password prompt Instead of that, you can... provide the password in a pgpass file or through the PGPASSWORD environment variable."

最显而易见的方法是通过控制台提醒你来输入密码,除此之外你还可以:

  • 把密码放在pgpass文件
  • 把密码放在PGPASSWORD环境变量里
  • 具体怎么配置pgpass文件和PGPASSWORD环境变量可以参考下面两篇官方文档。

https://www.postgresql.org/docs/9.0/static/libpq-pgpass.html https://www.postgresql.org/docs/9.0/interactive/libpq-envars.html

使用PGPASSWORD环境变量

Command-line There is no option to provide the password as a command line argument because that information is often available to all users, and therefore insecure. However, in Linux/Unix environments you can provide an environment variable for a single command like this:

PGPASSWORD=yourpass psql ...psql -h 192.168.1.8 -p 5432 -U lg -d mydb -c "select * from myschema.table"

命令行:psql命令行没有提供密码参数,因为这样的话密码很可能会被所有用户知道,这样不安全。但是在Linux/Unix环境中你可以像下面这个命令一样,搞个环境变量即可:

PGPASSWORD=yourpass psql -h 192.168.1.8 -p 5432 -U lg -d mydb -c "select * from myschema.table"
相关推荐

关注公众号
获取免费资源

随机推荐


Copyright © Since 2014. 开源地理空间基金会中文分会 吉ICP备05002032号

Powered by TorCMS

OSGeo 中国中心 邮件列表

问题讨论 : 要订阅或者退订列表,请点击 订阅

发言 : 请写信给: osgeo-china@lists.osgeo.org