关于ruby:由于ACTIVE RECORD,无法启动Rails服务器连接到postgres:CONNECTION NOT ESTABLISHED

Unable to start Rails server to connect to postgres because of ACTIVE RECORD : CONNECTION NOT ESTABLISHED

1
I have installed ruby 1.9.3-p327, and my databse is postgres.I modified the database.yml page also..as:evelopment:

适配器:postgresql
数据库:db_pchamara
用户名:db_test_user
密码:密码
主持人:192.168.1.101
游泳池:5

测试:
适配器:postgresql
数据库:db_pchamara.test
用户名:db_test_user
密码:密码
主持人:192.168.1.101
游泳池:5

生产:
适配器:postgresql
数据库:db_pchamara
用户名:db_test_user
密码:密码
主持人:192.168.1.101
游泳池:5
但我面临的问题是什么时候
我运行rails server它显示以下错误:它不是postgre db ..

但是如果运行ruby文件,它会从db获取数据:帮助我这个,.....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `
retrieve_connection'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'

  activerecord (3.2.9) lib/active_record/query_cache.rb:67:in `rescue in call'
  activerecord (3.2.9) lib/active_record/query_cache.rb:61:in `
call'
  activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'

  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `
_run__241814793__call__597619238__callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'

  activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `
run_callbacks'
  actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'

  actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `
call'
  actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'

  actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.9) lib/rails/rack/logger.rb:32:in `
call_app'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'

  activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.9) lib/rails/rack/logger.rb:16:in `
call'
  actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'

  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `
call'
  activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'

  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `
call'
  railties (3.2.9) lib/rails/engine.rb:479:in `call'

  railties (3.2.9) lib/rails/application.rb:223:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `
call'
  railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'

  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `
service'
  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'

  /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.9ms)
  Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (9.6ms)



This is my gemfile.lock

Gems included by the bundle:
  * actionmailer (3.2.9)
  * actionpack (3.2.9)
  * activemodel (3.2.9)
  * activerecord (3.2.9)
  * activeresource (3.2.9)
  * activesupport (3.2.9)
  * arel (3.0.2)
  * builder (3.0.4)
  * bundler (1.2.3)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.4.0)
  * erubis (2.7.0)
  * execjs (1.4.0)
  * hike (1.2.1)
  * i18n (0.6.1)
  * journey (1.0.4)
  * jquery-rails (2.1.4)
  * json (1.7.5)
  * mail (2.4.4)
  * mime-types (1.19)
  * multi_json (1.4.0)
  * pg (0.14.1)
  * polyglot (0.3.3)
  * rack (1.4.1)
  * rack-cache (1.2)
  * rack-ssl (1.3.2)
  * rack-test (0.6.2)
  * rails (3.2.9)
  * railties (3.2.9)
  * rake (10.0.2)
  * rdoc (3.12)
  * sass (3.2.3)
  * sass-rails (3.2.5)
  * sprockets (2.2.2)
  * thor (0.16.0)
  * tilt (1.3.3)
  * treetop (1.4.12)
  * tzinfo (0.3.35)
  * uglifier (1.3.0)


检查位于应用程序目录根目录中的Gemfile。

删除gem'sqlite'并添加gem'pg'然后保存。运行捆绑安装

安装gem的最佳方法是将它们添加到gem文件并运行bundle install。不建议运行"gem install -"

您还需要修改位于config文件夹中的database.yml并进行必要的调整以运行pg。


如果你遇到这种类型的错误,你必须检查三个文件..

1.database.yml
2. postgresql lib中的pg_hba.conf。
3.如果你在远程机器上工作,我们必须将我们的主机ip包含到database.yml文件中......

在创建项目时使用他的命令知道服务器你将使用postgresql ..

'rails new demo --database = postgresql'

那么只有pg gem文件才能加载到bundle ..

来到pg_hba.conf文件编辑为信任,它是md5。它会在您的IP地址附近。

md5-需要密码才能连接到db
信任 - 不要问密码

确保您的database.yml文件正确无误