“FATAL: role ”root“ does not exist” when running rake db:schema:load

五迷三道 提交于 2019-12-14 03:03:48

问题


i finished developing a little app, and try to put it into production. I copied the app to a new folder, created a new psql database with a new user, adjusted my database.yml file and try to run rake db:schema:load to get my database in the right state. Rake is able to connect to my db, since the first steps are executed, but after those, it aborts with the following message. As far as google tells me, it should be an issue with the user. However, since rake can execute the first steps, i doubt that i have an issue with it.

[root@l1vmgt08 web_qip_parser_v2]# rake db:schema:load    
-- enable_extension("plpgsql")
   -> 0.0171s
-- create_table("qip_changes", {:force=>:cascade})
   -> 0.0919s
-- create_table("users", {:force=>:cascade})
   -> 0.0989s
-- add_foreign_key("qip_changes", "users")
   -> 0.0042s
-- enable_extension("plpgsql")
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "root" does not exist

config/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

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

Psql output of my Dev and the new Prod user for privilege comparison:

postgres=# \l
                                                 List of databases
          Name          |       Owner       | Encoding |   Collate   |    Ctype    |       Access privileges        
------------------------+-------------------+----------+-------------+-------------+--------------------------------
my_dev_user_name        | postgres          | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres                  +
                        |                   |          |             |             | postgres=CTc/postgres         +
                        |                   |          |             |             | my_dev_db_name=CTc/postgres
 my_user_name           | postgres          | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres                  +
                        |                   |          |             |             | postgres=CTc/postgres         +
                        |                   |          |             |             | my_db_name=CTc/postgres

so it seems to me that iam trying to connect via UNIX socket, using the local user. I found some articles describing this issue. This should be fixed when i connect via TCP/IP, by simple adding "host: localhost" to my database.yml file. However, thats exactly what i have done, so i have no idea how to proceed

here my pg_hba.conf:

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

there is another application running on the server, which works. It has the same database.yml config set as i do.


回答1:


Might have happened due to absence of username statement for test environment. Please see this question



来源:https://stackoverflow.com/questions/54803489/fatal-role-root-does-not-exist-when-running-rake-dbschemaload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!