gpt4 book ai didi

ruby-on-rails - 启动从 ubuntu 上的 ruby​​ gem 下载的 postgres 服务器

转载 作者:行者123 更新时间:2023-11-29 14:04:17 25 4
gpt4 key购买 nike

当我从我的 Rails 应用程序运行 rake:db migrate 时,我得到了这个输出:

rake aborted!
PG::ConnectionBad: 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?

/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/ubuntu/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

在我的 gemfile 中有

gem 'pg'

在我的 database.yml 中有

default: &default
adapter: postgresql
encoding: unicode
pool: 5

development:
<<: *default
database: fake_lunch_hub_development

test:
<<: *default
database: fake_lunch_hub_test


production:
<<: *default
database: fake_lunch_hub_production
username: fake_lunch_hub
password: <%= ENV['FAKE_LUNCH_HUB_DATABASE_PASSWORD'] %>

这个设置曾经完美地连接到数据库,但我做了很多重构和重命名(该项目不再称为 fake_lunch_hub),我将项目从我的本地机器 (mac) 移到亚马逊 EC2 实例上(Ubuntu)。

Stackoverflow 上还有许多其他问题提供了使用 psql 的解决方案,但是当我运行命令时

psql

我明白了:

The program 'psql' can be found in the following packages:
* postgresql-client-common
* postgres-xc-client
Try: sudo apt-get install <selected package>

我不想下载新的 postgres 包,因为我已经从 gem 成功下载了它。

如何启动该服务器并接受连接?

编辑:

完整解决方案:

sudo apt-get install postgres
sudo su
su postgres
createuser ubuntu
createuser fake_lunch_hub
createdb fake_lunch_hub
exit
exit
rails server

解决问题

最佳答案

gem 只是 Ruby/Rails 与 Postgres 服务器通信的一种方式。 gem 本身包含自己的服务器。

您仍然需要安装一个:

sudo apt-get install postgresql  

关于ruby-on-rails - 启动从 ubuntu 上的 ruby​​ gem 下载的 postgres 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25060949/

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