PostgreSQL:使用密码脚本执行psql [英] Postgresql: Scripting psql execution with password

查看:1510
本文介绍了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。您不妨在 http://www.postgresql上调查密码验证的替代方法.org / docs / current / static / client-authentication.html

There are several ways to authenticate to postgresql. You may wish to investigate alternatives to password authentication at http://www.postgresql.org/docs/current/static/client-authentication.html.

要回答您的问题,基于认证。显而易见的方式是通过密码提示。除此之外,您可以在pgpass文件中或通过PGPASSWORD环境变量提供密码。请参阅:

To answer your question, there are a few ways provide a password for password-based authentication. 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. See these:

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

没有选项可以提供密码作为命令行参数,因为该信息通常对所有用户可用,因此不安全。但是,在Linux / Unix环境中,您可以为单个命令提供一个环境变量,如下所示:

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 ...

PGPASSWORD=yourpass psql ...

这篇关于PostgreSQL:使用密码脚本执行psql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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