Fabric Postgres密码在命令中 [英] fabric postgres password in command

查看:103
本文介绍了Fabric Postgres密码在命令中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个结构脚本,可将数据库转储到服务器上。而且我可以在带有PostgreSQL数据库的多台服务器上使用它。该命令很简单:

I have a fabric script that dumps database on server. And I can use it on multiple servers with the PostgreSQL database. The command is simple:

sudo("su postgres -c \"PGPASSWORD=%s pg_dump %s > /tmp/telemedia_newdb\""
% (HOST_SOURCE_DB_UPASS,HOST_SOURCE_DB))

但有时,Postgres根本不要求输入密码...

But sometimes, Postgres does not ask for a password at all ...

如果没有Postgres提示输入密码,此命令是否会失败? (或者我知道它不会提示,并且 HOST_SOURCE_DB_UPASS =’’)。我希望此代码可以使用密码,也可以不使用密码。

Will this command fail without a password prompting from Postgres? (Or I know that it will not prompt and HOST_SOURCE_DB_UPASS=''). I want THIS code to work with or without password.

推荐答案

这完全取决于您如何在 pg_hba.conf 。每个数据库群集都有一个单独的配置文件(实际上是每个端口),并且数据库之间的设置可能会有所不同。

It all depends on how you set up access to your database in pg_hba.conf. There is a separate config file per database cluster (effectively per port) and settings can be different from database to database.

因此,是的,如果已进行设置这样,系统用户 postgres 将可以无密码访问某些数据库,但会提示您输入其他用户的密码。 默认是系统用户 postgres 以相同名称的数据库用户( postgres )。

So, yes, if you have set it up that way, then the system user postgres will have password-less access to some databases but is prompted to enter a password for others. The default is that the system user postgres has password-less access to every database as database user of the same name (postgres).

如果您在命令中使用环境变量 PGPASSWORD ,但不需要密码,它将被静默忽略。

If you provide a password in the command with the environment variable PGPASSWORD, but no password is needed, it will be ignored silently.

但是,我引用了手册此处


PGPASSWORD(...)出于安全原因,不建议使用此环境变量。

PGPASSWORD (...) Use of this environment variable is not recommended for security reasons.

您可以使用密码文件自动提供密码(在Unix系统上为 .pgpass )。 pg_dump 将使用它。

You can use a password file to provide passwords automatically (.pgpass on Unix systems). pg_dump will use it.

最后,考虑命令行选项

--no-password
--password

强制pg_dump提示或不提示输入密码。如果需要密码但被-无密码禁用,则pg_dump将失败。

to force pg_dump to either prompt or not prompt for a password. If a password is required but disabled by --no-password, pg_dump will fail.

我将为系统用户 postgres 为配置文件<$ c $中的每个数据库启用无密码访问 c> pg_hba.conf 。使用 peer ident 身份验证方法。然后,您不必提供密码,脚本将始终有效:

I would enable password-less access for the system user postgres to every database in the config file pg_hba.conf. Use peer or ident authentication methods. Then you don't have to provide a password and the script will always work:

local    all         postgres             ident

您的脚本将简化为(未经测试):

Your script would be simplified to (untested):

sudo("su postgres -c \"pg_dump %s > /tmp/telemedia_newdb\"" % (HOST_SOURCE_DB))

这篇关于Fabric Postgres密码在命令中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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