postgresql:.pgpass在Windows / cygwin上不起作用

问题描述 投票:0回答:1

我无法让.pgpass在Windows / cygin上工作

我在Windows 10的psql版本12.0上安装了pgAdmin4。

我正在使用cygwin,编写bash脚本来对通过云提供商安装的PG数据库执行各种操作。

如果我在bash脚本中指定了这些环境变量,那么一切都会很好:

export PGUSER=<pguser>
export PGPASSWORD=<pgpassword>
export PGHOSTADDR=<ip-address>
export PGPORT=5432

但是如果不是,我不将这些env vars包含在bash脚本中,而是创建一个.pgpass文件:$ HOME / .pgpass并输入如下一行:

hostname:port:database:username:password

并运行脚本,它尝试连接到'localhost',好像找不到.pgpass文件。


我收到此错误:

Running: [./myscript.sql]

psql: error: could not connect to server: could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?


我试图像这样在bash脚本中明确指定:

export PGPASSFILE=$HOME/.pgpass

并且它仍然无法正常工作,我收到相同的错误消息,它忽略了PGPASSFILE env变量。


我将.pgpass文件的权限设置为0600,所以这不是问题。

ls -l .pgpass
-rw------- 1 <user> None 49 Feb 12 23:01 .pgpass
postgresql cygwin psql
1个回答
0
投票

运行脚本,它尝试连接到'localhost',好像找不到.pgpass文件。

。pgpass不会告诉libpq(psql使用的是哪个)连接到哪个主机。相反,libpq首先确定主机,然后在.pgpass中查找该特定主机(或通配符)。因此,似乎损坏的东西是PGHOSTADDR,而不是.pgpass。

© www.soinside.com 2019 - 2024. All rights reserved.