Error accessing localhost:3000 with postresql set as the development db in Rails app
所以我通常在开发中使用Sqlite3但想尝试PG。 这是我得到的错误。 为什么?
PG:: ConnectionBad
无法连接到服务器:连接被拒绝服务器是否在主机"localhost"(127.0.0.1)上运行并接受端口5432上的TCP / IP连接? 无法连接到服务器:连接被拒绝服务器是否在主机"localhost"(:: 1)上运行并接受端口5432上的TCP / IP连接? 无法连接到服务器:连接被拒绝服务器是否在主机"localhost"(fe80 :: 1)上运行并接受端口5432上的TCP / IP连接?
1 2 | $ which psql $ /usr/LOCAL/bin/psql |
这看起来是对的。
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 | **DATABASE.yml** development: adapter: postgresql encoding: unicode DATABASE: timetracker_development pool: 5 username: postgres password: host: localhost test: adapter: postgresql encoding: unicode DATABASE: timetracker_test pool: 5 username: postgres password: host: localhost production: adapter: postgresql encoding: unicode DATABASE: timetracker_production pool: 5 username: timetracker password: |
这里没什么可疯狂的。
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 | Gemfile SOURCE 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.0.4' # USE postgresql AS the DATABASE FOR Active Record gem 'pg' # USE SCSS FOR stylesheets gem 'sass-rails', '~> 4.0.2' # USE Uglifier AS compressor FOR JavaScript assets gem 'uglifier', '>= 1.3.0' # USE CoffeeScript FOR .js.coffee assets AND views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme FOR more supported runtimes # gem 'therubyracer', platforms: :ruby # USE jquery AS the JavaScript library gem 'jquery-rails' # Turbolinks makes following links IN your web application faster. READ more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs WITH ease. READ more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 1.2' GROUP :doc do # bundle EXEC rake doc:rails generates the API UNDER doc/api. gem 'sdoc', require: FALSE END |
主要是新Rails 4应用程序的默认值。
谢谢你的帮助。
首先,确保Postgres实际上正在运行。
1 | ps aux | grep postgres |
你也可以这样做:
1 | netstat -an | grep 5432 |
应该报告它正在监听0.0.0.0:5432或127.0.0.1:5432,我想。
它应该列在这些命令的输出中。 如果它没有运行,请启动它。
接下来,确保列出的用户,密码和数据库确实存在。
1 | psql DATABASE USERNAME |
如果允许您进入,请运行