如何以非交互方式为PostgreSQL的createdb提供密码? [英] How to provide a password for PostgreSQL's createdb non-interactively?

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

问题描述

我在phing中有一个任务,在测试之前,我会删除数据库(如果存在)并创建它.这是在詹金斯上运行的. 我想用createdb这样做:

I have a task in phing where before tests I drop the database if exists and create it. This is run on Jenkins. I want to do it with createdb like this:

<exec command="createdb my_database" />

问题是createdb要求我进行身份验证,并且添加-Umy_user参数不是问题-问题是我无法在createdb命令中指定密码.而且我不想为系统用户(在这种情况下为"jenkins")创建角色.有解决方案吗?

The thing is that the createdb is asking me to authenticate and adding -Umy_user parameter is not a problem - the issue is that I cannot specify a password in the createdb command. And I don't want to create a role for the system user ("jenkins" in this case). Is there a solution for that ?

推荐答案

createdb将使用 PGPASSWORD 环境变量(如果已设置),这是在非交互式运行中提供密码的一种简单方法.

createdb will use the PGPASSWORD environment variable if it's set, that's one simple way of providing a password in non-interactive runs.

另一种选择是设置 .pgpass UNIX用户启动createdb的主目录中的文件.

Another option would be to set up a .pgpass file in the home directory of the unix user launching the createdb.

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

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