简体   繁体   中英

PostgreSQL requires password after changing Rails DB setup from database name to url

Changed the DB setup of Rails ( config/database.yml ) from:

development:
  <<: *default
  database: my_app_development

to:

development:
  <<: *default
  url: postgres://postgres@localhost:5432/my_app_development

Started getting the following error:

rails db:migrate:reset
=> rails aborted!
=> PG::ConnectionBad: fe_sendauth: no password supplied

OS: Ubuntu 18.04 LTS

The issue was that pg_hba.conf has different rules for this scenario. The following line might look like it enables all connections

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             all                                     peer (or trust)

But there can be other offending ones, in my case:

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

Changing this line from md5 to trust resolved the issue. Keep in mind that this is not safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM