所以我通常在开发中使用Sqlite3但想尝试PG . 这是我得到的错误 . 为什么?
PG :: ConnectionBad无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接?无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(:1)上运行并接受端口5432上的TCP / IP连接?无法连接到服务器:连接被拒绝服务器是否在主机“localhost”(fe80 :: 1)上运行并接受端口5432上的TCP / IP连接?
$ which psql
$ /usr/local/bin/psql
这看起来是对的 .
**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:
这里没什么疯狂的事 .
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应用程序的默认值 .
谢谢你的帮助 .
1 回答
首先,确保Postgres实际上正在运行 .
which postgres
只是告诉你它在哪里,它没有运行_473788 .你也可以这样做:
应该报告它正在监听0.0.0.0:5432或127.0.0.1:5432,我想 .
它应该列在这些命令的输出中 . 如果它没有运行,请启动它 .
接下来,确保列出的用户,密码和数据库确实存在 .
如果允许您进入,请运行
\dt
并查看它是否告诉您有关数据库的任何信息 . 我'd expect it to be blank if it'是一个新的数据库 . 如果您收到密码提示但不接受密码,则仍需要创建用户 . 您可以使用此页面http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/获取有关安装和配置它的完整说明 .