【问题标题】:Rails in linux. Is the server running on host “localhost” (::1) and accepting TCP/IP connections on port 5432?Linux中的导轨。服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接?
【发布时间】:2020-12-24 02:05:07
【问题描述】:

Disclamer:我经历了相同的标题,但没有一个能帮助我解决我的问题。

我安装并启动了一个 postgresql 服务器: 我首先删除pgdata/postmaster.pid 以确保与其他帖子的问题不同。 然后
pg_ctl start
lsof | grep 5432 -> 什么都没有

pg_ctl start -> ...正在侦听 Unix 套接字“sockets/.s.PGSQL.5432”...数据库系统已准备好接受连接... lsof | grep 5432 -> postgres 1495 用户名 4u unix 0x0000000000000000 0t0 16163716 sockets/.s.PGSQL.5432 type=STREAM

然后我选择:rake db:setup,然后我得到:

could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
Couldn't create 'seqresults-test' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

然后我就可以用客户端访问数据库了。

$ psql

然后

postgres=#

请帮忙!在我看来,这一切都像是黑魔法,但它不起作用。
如果有人能简要解释一下这是如何工作的,我也将不胜感激。

【问题讨论】:

  • 你可以试试这个方法吗? stackoverflow.com/questions/65427026/…
  • @Danizavtz。谢谢你。我没有 sudo 权力。有什么选择?
  • 你试过 docker 吗?
  • @Danizavtz。不,我不知道怎么做。
  • 托管服务可以替代您吗? aws 或谷歌 gcp。如果你在 heroku 中有一个实例,你可以免费拥有一个数据库,直到 10K 行。 atlas (mongodb) 中还有 500Mb 的免费空间。如果没有,也许你可以使用 sqlite(本地文件系统)。有一个 postgresql 托管服务,叫做大象sql(我没用过)。

标签: ruby-on-rails linux postgresql


【解决方案1】:

看起来您的 postgres 正在侦听 unix 套接字(一种特殊的文件),而不是 tcp 的。

您可以尝试通过该套接字进行连接(您系统上的位置可能会有所不同,您需要.s.PGSQL.5432 文件所在的目录):

# database.yml
  host: '/var/run/postgresql'
  database: ...

【讨论】:

  • 如何让 Postgres 监听 tcp 套接字?
猜你喜欢
  • 2018-01-20
  • 1970-01-01
  • 2018-12-17
  • 2021-11-29
  • 1970-01-01
  • 2017-06-09
  • 1970-01-01
  • 1970-01-01
  • 2016-05-30
相关资源
最近更新 更多