gpt4 book ai didi

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

转载 作者:数据小太阳 更新时间:2023-10-29 06:40:38 24 4
gpt4 key购买 nike

当我运行 rake db:migrate 或运行 rails s 命令时,我得到同样的错误:

Error : 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"?

当我尝试 rails s 时,浏览器出现错误。

这是我的database.yml

default: &default
adapter: postgresql
encoding: unicode

pool: 5

development:
<<: *default
database: books_development




test:
<<: *default
database: books_test



production:
<<: *default
database: books_production
username: abd
password: <%= ENV['BOOKS_DATABASE_PASSWORD'] %>

注意:我有数据库 books_developmentbooks_test
;当我尝试 sudo/etc/init.d/postgresql start

时,postresql 运行没有问题

我确实跑了:

create database books_development;
create database books_test;

在 psql 控制台中。并且说成功了

我尝试了很多解决方案,昨天我一直在寻找解决方案,但相关问题中的解决方案没有解决我的错误。

我有 postgresql-9.4(最新的)和 xubuntu 14.04

有什么想法吗?

最佳答案

为 Debian 或 Debian 衍生产品(如 Ubuntu)打包的 PostgreSQL 的约定是使用 /var/run/postgresql 作为 Unix 域套接字的目录。另一方面,自编译的 postgres 客户端库的约定是使用 /tmp,除非以其他方式自行配置。

因此,两者不匹配的常见根本原因是自编译的客户端内容与预编译的服务器端包的混合(即使客户端和服务器安装在同一台机器上,客户端和服务器-side 仍然不同并且可能不同步)。

按照提问者的建议从 /tmp 软链接(soft link)到这个目录是可行的,除了链接会在每次重启时丢失,因为通常 /tmp 是空的重启时。

更好的选择是在 database.yml 中添加一个条目:

  • 或者host:/tmp如果真正的socket路径是/tmp(自编译服务端,打包客户端)

  • 或者host:/var/run/postgresql如果是真正的socket路径/var/run/postgresql/(打包服务器,自编译客户端) .

当主机字段中的值以斜杠字符开头时,postgres 库知道它是本地套接字目录的位置而不是主机名。目录 .s.PGSQL.portnumber 中的文件名是生成的,不能指定,只能指定目录。

另一种可能性是将自编译的软件包配置为尽可能接近 Debian,覆盖默认值。

关于ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28925848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com