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

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

问题描述

我正在尝试使用Shell脚本来自动化数据库创建过程,有一件事我遇到了障碍,即将密码传递给

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"

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

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

推荐答案

来自

拥有〜/.pgpass文件也很方便,以避免定期输入密码.有关更多信息,请参见第30.13节.

...

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

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天全站免登陆