-1

So I have typically used Sqlite3 in Development but wanted to try PG. Here is the error I got. Why?

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? could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?

$ which psql
$ /usr/local/bin/psql 

This looks right.

**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:

Nothing crazy going on here.

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

Mostly defaults for new Rails 4 app.

Thanks for your help.

user3174983
  • 85
  • 3
  • 12
  • possible duplicate of [PG::ConnectionBad - could not connect to server: Connection refused](http://stackoverflow.com/questions/19828385/pgconnectionbad-could-not-connect-to-server-connection-refused) – Daniel Vérité Apr 29 '14 at 09:51

1 Answers1

1

First, make sure Postgres is actually running. which postgres just shows you where it is found, it doesn't mean it's running.

ps aux | grep postgres

You can also do:

netstat -an | grep 5432

That should report that it's listening on either 0.0.0.0:5432 or 127.0.0.1:5432, I imagine.

It should be listed in the output of those commands. If it's not running, start it.

Next, make sure the user, password, and database listed actually exist.

psql DATABASE USERNAME

If that lets you in, run \dt and see if it tells you any information about your DB. I'd expect it to be blank if it's a new database. If you get a password prompt and it doesn't accept your password, you still need to create the user. You can use this page, http://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/, for full instructions on installing and configuring it.

subvertallchris
  • 5,282
  • 2
  • 25
  • 43