服务器是否在本地运行并接受Unix域套接字上的连接/var/run/postgresql/.s.PGSQL.5432“;?

服务器是否在本地运行并接受Unix域套接字上的连接/var/run/postgresql/.s.PGSQL.5432“;?,postgresql,flask,Postgresql,Flask,执行以下命令时遇到主题中的错误 heroku run python manage.py db upgrade 该应用程序在本地服务器上运行良好,但不会迁移到带有postgres db的heroku 我尝试了无数的解决方案,但都没有奏效 启动数据库时,下面是出现的消息 aiting for server to start....2020-10-11 20:14:58.637 +04 [11244] LOG: starting PostgreSQL 13.0 on x86_64-apple-da

执行以下命令时遇到主题中的错误

heroku run python manage.py db upgrade
该应用程序在本地服务器上运行良好,但不会迁移到带有postgres db的heroku

我尝试了无数的解决方案,但都没有奏效

启动数据库时,下面是出现的消息

aiting for server to start....2020-10-11 20:14:58.637 +04 [11244] LOG:  starting PostgreSQL 13.0 on x86_64-apple-darwin19.4.0, compiled by Apple clang version 11.0.0 (clang-1100.0.33.8), 64-bit
2020-10-11 20:14:58.641 +04 [11244] LOG:  listening on IPv6 address "::1", port 5432
2020-10-11 20:14:58.641 +04 [11244] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-10-11 20:14:58.644 +04 [11244] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-10-11 20:14:58.672 +04 [11246] LOG:  database system was interrupted; last known up at 2020-10-11 20:11:13 +04
2020-10-11 20:14:59.020 +04 [11246] LOG:  database system was not properly shut down; automatic recovery in progress
2020-10-11 20:14:59.034 +04 [11246] LOG:  redo starts at 0/1671320
2020-10-11 20:14:59.034 +04 [11246] LOG:  invalid record length at 0/1671358: wanted 24, got 0
2020-10-11 20:14:59.034 +04 [11246] LOG:  redo done at 0/1671320
2020-10-11 20:14:59.067 +04 [11244] LOG:  database system is ready to accept connections
 done
server started

问题是,;来自错误'/var/run/postgresql/.s.PGSQL.5432'',而不是来自日志“侦听Unix套接字”/tmp/.s.PGSQL.5432”。首先,我会尝试将您的
DSN
更改为使用
host=
,这样您就不会尝试连接到套接字。然后,您需要弄清楚为什么
psycopg2
正在寻找不同的套接字。通常,在一个发行版上编译/使用
libpq
时会发生这种情况,该发行版将套接字置于
/var/run/
位置,然后在另一个发行版上运行,其中套接字位于
/tmp/
,您只需要重新启动服务器的psql。请小心使用此数据库:

sudo service postgresql restart

我突然犯了同样的错误。它解决了。它与psycopg2.connect(dsn)

无关,除非您的
conn
dsn指向此位置,否则它将无法工作。你需要在你的问题中提供完整的信息,这样其他人就不必通过所有的评论来找到它。试试我在回答中的建议,即指向不是套接字的东西。换句话说,在一个实际的主机名或地址。感谢您尝试帮助Adrian,但无法理解需要做什么。首先,请提供有关
dsn
In
conn=\u connect(dsn,connection\u factory=connection\u factory,**kwasync)的信息
is?您没有在my macWell上明确设置任何dsn,这是您的问题。您需要在
psycopg2.connect(dsn)
中为
dsn
指定一些内容,无论代码中调用了什么。否则它将使用默认值。另外,我猜您已经安装了
psycopg2 binary
sudo service postgresql restart