如何以非交互方式为“psql"指定密码? [英] How do I specify a password to 'psql' non-interactively?

查看:90
本文介绍了如何以非交互方式为“psql"指定密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 shell 脚本自动执行数据库创建过程,并且我在将密码传递给 psql.这是shell脚本中的一些代码:

psql -U $DB_USER -h localhost -c"$DB_RECREATE_SQL"

如何以非交互方式将密码传递给 psql?

解决方案

来自 官方文档:

<块引用>

有一个 ~/.pgpass 文件也很方便,以避免经常输入密码.有关详细信息,请参阅第 30.13 节.

...

<块引用>

此文件应包含以下格式的行:

主机名:端口:数据库:用户名:密码

<块引用>

将使用第一行中与当前连接参数匹配的密码字段.

I am trying to automate database creation process with a shell script and one thing I've hit a road block with passing a password to psql. Here is a bit of code from the shell script:

psql -U $DB_USER -h localhost -c"$DB_RECREATE_SQL"

How do I pass a password to psql in a non-interactive way?

解决方案

From the official documentation:

It is also convenient to have a ~/.pgpass file to avoid regularly having to type in passwords. See Section 30.13 for more information.

...

This file should contain lines of the following format:

hostname:port:database:username:password

The password field from the first line that matches the current connection parameters will be used.

这篇关于如何以非交互方式为“psql"指定密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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