【问题标题】:Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?
【发布时间】:2020-10-11 16:31:30
【问题描述】:

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

heroku run python manage.py db upgrade
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) 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 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

【问题讨论】:

    标签: postgresql flask


    【解决方案1】:

    你只需要重新启动服务器的 psql。小心这个数据库:

    sudo service postgresql restart
    

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

    【讨论】:

      【解决方案2】:

      问题是;来自错误 '"/var/run/postgresql/.s.PGSQL.5432"?",而不是来自日志 "listening on Unix socket "/tmp/.s.PGSQL.5432"。首先,我会尝试将您的DSN 更改为使用host=,这样您就不会尝试连接到套接字。然后你需要理清为什么psycopg2 正在寻找不同的套接字。通常,当它在一个将套接字置于/var/run/ 的发行版上针对libpq 编译/使用,然后在另一个套接字位于/tmp/ 的发行版上运行时,就会发生这种情况。

      【讨论】:

      • 除非您的conn 的dsn 指向它,否则它将不起作用。您需要提供完整的信息并在您的问题中这样做,这样其他人就不必通过所有的 cmets 才能找到它。试试我在回答中的建议,将host指向不是套接字的东西。换句话说,在实际的主机名或地址。
      • 感谢您尝试帮助 Adrian,但无法理解需要做什么。
      • 在您的问题开始时,请提供dsn in conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 的信息?
      • 没有在我的 mac 上明确设置任何 dsn
      • 那是你的问题。您需要在psycopg2.connect(dsn) 中为dsn 指定一些内容,无论在代码中调用什么。否则它将使用默认值。另外我猜你安装了psycopg2-binary
      猜你喜欢
      • 2015-08-13
      • 2019-01-24
      • 2015-05-09
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多