1

Studying at http://ruby.railstutorial.org/ version 3.2

Stucked in the end of 6.2.1 section with the following:

$ bundle exec rake db:test:prepare
rake aborted!
FATAL:  no pg_hba.conf entry for host "192.168.108.1", user "sample_user", database "postgres", SSL on
FATAL:  no pg_hba.conf entry for host "192.168.108.1", user "sample_user", database "postgres", SSL off

Tasks: TOP => db:test:load => db:test:purge

192.168.108.1 is my ip. Why is it looking for it, if I have another entry in database.yml? User sample_user is owner of all databases and has CREATEDB on them. I can successfuly connect to any database on 192.168.108.2 with psql from 192.168.108.1

How cat I overcome it, still using remote postgres?

Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.3'
gem 'bootstrap-sass', '2.0.0'
gem 'pg', '0.12.2'

group :development, :test do
  gem 'rspec-rails', '2.9.0'
end

group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

group :development do
gem 'annotate', '~> 2.4.1.beta'
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'spork', '0.9.0'
end

database.yml

common: &common
    adapter: postgresql
    username: sample_user
    password: qwerty123
    host: 192.168.108.2

development:
    <<: *common
    database: sample_db_dev

test:
    <<: *common
    database: sample_db_tst

production:
    <<: *common
    database: sample_db_pro

pg_hba.conf on 192.168.108.2

host    sample_db_dev   sample_user 192.168.108.1/32   md5
host    sample_db_tst   sample_user 192.168.108.1/32   md5
host    sample_db_pro   sample_user 192.168.108.1/32   md5

have no local pg_hba.conf on 192.168.108.1

ruby 1.9.3p125 Rails 3.2.3 psql (PostgreSQL) 8.4.11

1 Answer 1

1

pg_hba.conf is a file on the PostgreSQL server to define which users are allowed to connect to which databases from which hosts using what authentication methods.

http://www.postgresql.org/docs/8.4/interactive/auth-pg-hba-conf.html

So, that message is telling you that the server hasn't been told to allow the connection you are attempting. You must either make a connection which PostgreSQL has been told to allow, or tell it to allow this one by updating the pg_hba.conf file.

If you don't have access to server, and whoever does has not chosen to grant you PostgreSQL connection rights, you can't connect. That's the nature of security.

Sign up to request clarification or add additional context in comments.

4 Comments

did you saw my local database.yml and my pg_hba.conf from DB server?
The lines you show from pg_hba.conf don't show any permissions for the postgres database mentioned in the error message.
Thank you. Didn't know that there is system database "postgres". All works.
That was added just to provide a standard place to connect when you need to do "global" activities, like listing the databases. In PostgreSQL you need to connect to some database to be able to read shared tables (like pg_database). You can probably see the benefit of having a database which is always present even though it's not used to store anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.