在没有密码提示的 bash 脚本中运行 PostgreSQL CLI (psql)? [英] Run PostgreSQL CLI (psql) in bash script without password prompt?

查看:56
本文介绍了在没有密码提示的 bash 脚本中运行 PostgreSQL CLI (psql)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以用户 postgres 身份通过 bash 脚本运行 PostgreSQL CLI (psql) 会导致发送密码提示,即使我可以在没有密码的情况下手动运行它.当我尝试将 -w 放入脚本时,会发生此错误:

Running the PostgreSQL CLI (psql) through a bash script as user postgres causes a password prompt to be sent, even though I can run it manually without a password. When I try to put -w in the script, this error occurs:

psql:fe_sendauth:未提供密码

psql: fe_sendauth: no password supplied

我可以在没有密码的情况下以自动方式运行 psql 吗?

Can I run psql in an automated way without a password?

推荐答案

您可以使用密码文件 pgpass.conf 或使用 PGPASSWORD 变量.

You can use password file pgpass.conf or use PGPASSWORD variable.

对于本地开发或者如果安全不是问题,您还可以将 PostgreSQL 配置为在 trust 认证模式,通过修改你的 pg_hba.conf 文件.

For local development or if security isn't an issue, you could also configure PostgreSQL to run in trust authentication mode by modifying your pg_hba.conf file.

这篇关于在没有密码提示的 bash 脚本中运行 PostgreSQL CLI (psql)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆