大网数据广告活动
服务器运维问答

Using PGPASSWORD variable does not seem to work any more on Postgresql 9.3

· 52CE 我爱测

In Posgresql you can set a variable called PGPASSWORD (and PGUSER ) so you don't have to use password when using postgresql commands such as psql or pg_dump But I am a bit confused because I can't get it to work on Postgresql 9.3…

问题原文

原帖链接 · Ulukai · CC BY-SA 3.0

In Posgresql you can set a variable called PGPASSWORD (and PGUSER) so you don't have to use password when using postgresql commands such as psql or pg_dump

But I am a bit confused because I can't get it to work on Postgresql 9.3.10 and it's still documented on their site as if it should work.

so commands like

PGPASSWORD=password psql -l

will not work.

Neither can I declare them before hand such as

PGUSER=root

PGPASSWORD=password

psql -l

It still asks for password (although in this case, it uses the root user as it should)

The only way I have got it to work somehow was by doing the .pgpass file but it only works when using a specific database, asterisk doesn't work and it only works with pg_dump, not all postgresql commands like psql -l:

localhost:5432:*:root:password

These are my pg_hba.conf settings if it helps any:

local   all             root                                md5

    # TYPE  DATABASE        USER            ADDRESS                 METHOD

    # "local" is for Unix domain socket connections only
    local   all             all                                     peer
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            md5
    # IPv6 local connections:
    host    all             all             ::1/128                 md5

已采纳解答

原帖链接 · Ulukai · CC BY-SA 3.0

Turns out the way to make it work with all databases and commands is by adding the following in the .pgpass file:

localhost:5432:dbname:user:password localhost:5432:*:user:password

If you add only the second line it won't work, you need to add both.

Bizarre.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。