Sqitch无法连接到正在运行的Postgres实例

问题描述

我在OSX上有一个Postgres 9.6实例,该实例已启动并正在运行,但是当我在具有sqitch status的工作目录中尝试sqitch.conf时,Sqitch会引发以下错误

$ sqitch status
# On database db:pg:my_db
Could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGsql.5432"?

这很奇怪,因为我已经通过检查其状态并直接登录来检查Postgres是否正在运行:

$ pg_isready 
/tmp:5432 - accepting connections

$ psql -U postgres
psql (9.6.19)
Type "help" for help.
postgres=#

sqitch似乎只是一个问题。

有关更多详细信息,此Postgres是通过brew install postgresql@9.6安装的,位于认目录中:

$ which psql
/usr/local/opt/postgresql@9.6/bin/psql

关于Sqitch,我尝试同时使用Homebrew和Docker(我目前的方法)进行安装。 docker安装基于官方说明:

docker pull sqitch/sqitch
curl -L https://git.io/JJKCn -o sqitch && chmod +x sqitch
./sqitch status

我也尝试使用psql显式设置sqitch config --user engine.pg.client /usr/local/opt/postgresql@9.6/bin/psql

无论如何,我仍然可以通过任何sqitch命令获得以下信息:

$ sqitch status
# On database db:pg:my_db
Could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGsql.5432"?

我不确定我缺少什么,可以使用一些输入信息。预先感谢。

解决方法

我不知道安装了 Brew 的 Sqitch 是怎么回事,但是当您从 Docker 映像运行它时,该容器内部没有运行 Postgres,因此与 localhost 的连接将失败。您需要连接到容器外的 Postgres。如果您在 Mac 上运行它,这很简单:确保 Postgres is listening on the IP ports,而不仅仅是 Unix 域套接字,以及 specify host.docker.internal as the host name,如下所示:

sqitch status db:pg://host.docker.internal/my_db

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...