使用postgresql时如何将rails应用程序连接到服务器?

问题描述 投票:0回答:1

我有一个使用postgresql数据库的rails应用程序。这是我第一次使用它。已安装postgresql并且pgAdmin加载正常,但没有与任何服务器的连接。奇怪的是,我已经连接到localhost:3000之前使用此应用程序,但现在我在尝试连接时收到以下错误消息:

PG::ConnectionBad

could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

Extracted source (around line #56):

    ### Convenience alias for PG::Connection.new.
    def self::connect( *args )
        return PG::Connection.new( *args )
    end

database.yml文件:

default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000
  encoding: unicode
  username: postgres 
  password: #not sure what to put here

development:
  <<: *default
  database: nutri_development

test:
  <<: *default
  database: nutri_test

production:
  <<: *default
  database: nutri_production
  prepared_statements: false
  encoding: unicode

到目前为止,我已经看过关于设置postgresql的youtube视频并阅读指南,但在我的情况下,有些东西缺失,比如连接到服务器。我在这里找不到这个问题的答案。我完全迷失了这个,所以请一步一步地提出建议。 postgresql对我来说是全新的。如果有任何其他文件我应该在编辑中发布让我知道。

ruby-on-rails postgresql
1个回答
0
投票

如果你安装PostgreSQL然后点击这样的图标

enter image description here

如果您之前没有设置密码,那么软件要求设置密码然后在您的database.yml文件上使用它,如果没有要求密码,那么您可以手动创建,点击打开左侧的服务器pg admin仪表板server->PostgreSQL->Login/Group->postegres

enter image description here

右键单击鼠标然后转到属性单击以Definition选项卡然后设置您的密码。

就是这样!

希望能有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.