首页 文章

工头无法连接到potgresql服务器(Rails)

提问于
浏览
3

这是我第一次使用postgresql . 我已经检查过,服务器似乎肯定正在运行,但是当我开始工头时,我收到了这个错误

[...]postgresql_adapter.rb:1206:in `initialize': could not connect to server: No such file or directory (PG::Error)

有什么想法会出错吗?

谢谢

更新:

我打开了pgAdmin,db被设置为侦听端口8000而不是5432(这似乎是rails想要的) . 我尝试创建一个新连接并将其设置为5432但我收到此错误:

服务器不听

服务器不接受连接:连接库报告

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?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?

2 回答

  • 1

    更换端口对我不起作用 . 我使用Postgres.app在Mac上安装了postgres

    我不得不更新Rails数据库配置(database.yml)以添加主机字段并将其设置为localhost并删除用户名和密码字段

    development:
      adapter: postgresql
      encoding: unicode
      database: project_development
      host: localhost
      pool: 5
    

    修复后,错误是关于我连接到的数据库不存在 . 要解决此问题,请使用psql连接到postgres并创建数据库

    CREATE DATABASE project_development;
    

    用您的案例替换正确的DB名称 .

    Postgres.app文档还提供了在其他环境中配置的其他信息http://postgresapp.com/documentation#toc_3

  • 0

    我通过修改 database.yml 文件让Foreman再次工作 . 我不得不将端口更改为 8000 (postgres正在监听) .

相关问题