我在OSX上有一个Postgres 9.6实例,它已经启动并运行,但当我在带有sqitch.conf
的工作目录中尝试sqitch status
时,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
我试着用sqitch config --user engine.pg.client /usr/local/opt/postgresql@9.6/bin/psql
显式设置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正在侦听IP端口,而不仅仅是Unix域套接字,并指定host.docker.internal
作为主机名,如下所示:
sqitch status db:pg://host.docker.internal/my_db