2

old thread

i try to set up a postgres database and run into the following error when executing "rake db:schema:load". So it seems that rails tries to connect to my DB using a unix socket, instead of tcp/ip, which i have configured (refer to my database.yml below). I dont get why this is happening. I stumbled over the following thread, which confirms that i have set up my database.yml correct. click here. One idea was to change in the postgres config the method: peer for type: local to md5. However, as far as i understand the postgres config, my second line should do the job. Furthermore, another rails app is running on the same server using tcp/ip, so i expect the psql config to be correct. I also compared the database.yml files and they are the same

[root@myserver app]# rake db:schema:load                                    
-- enable_extension("plpgsql")
   -> 0.0166s
-- create_table("qip_changes", {:force=>:cascade})
   -> 0.0494s
-- create_table("users", {:force=>:cascade})
   -> 0.0539s
-- add_foreign_key("qip_changes", "users")
   -> 0.0037s
-- enable_extension("plpgsql")
rake aborted!
PG::ConnectionBad: FATAL:  Peer authentication failed for user "my_user_name"

pg_hba.conf:

     # TYPE  DATABASE        USER            ADDRESS                 METHOD
     local   all             all                                     peer
     host    all         all         127.0.0.1/32          md5

database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: my_db_name
  username: my_user_name
  password: my_password
  host: localhost
  port: 5432

test:
  <<: *default
  database: my_db_name
  username: my_user_name
  password: my_password
  host: localhost
  port: 5432

production:
  <<: *default
  database: my_db_name
  username: my_user_name
  password: my_password
  host: localhost
  port: 5432
Bastian
  • 177
  • 2
  • 12

1 Answers1

0

If you enter your database information as a url, it will properly connect via tcp/ip. I would love if we didn't have to enter the db info this way as it kind of sucks to look at, and is harder to maintain.

default: &default
  adapter: postgresql
  encoding: unicode

development:
  <<: *default
  # Rails 6 requires us to put this in as a url in order to force tcp/ip
  url: postgresql://postgres::example@localhost:5432/dev?pool=5
Vox
  • 161
  • 2
  • 9