“致命:角色“根"不存在"运行 rake db:schema:load 时 [英] "FATAL: role "root" does not exist" when running rake db:schema:load

查看:35
本文介绍了“致命:角色“根"不存在"运行 rake db:schema:load 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了一个小应用程序的开发,并尝试将其投入生产.我将应用程序复制到一个新文件夹,使用新用户创建了一个新的 psql 数据库,调整了我的 database.yml 文件并尝试运行 rake db:schema:load 以使我的数据库处于正确的状态.Rake 能够连接到我的数据库,因为执行了第一步,但在这些步骤之后,它会中止并显示以下消息.据谷歌告诉我,这应该是用户的问题.然而,由于 rake 可以执行第一步,我怀疑我有问题.

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:

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

我的 Dev 和新的 Prod 用户的 Psql 输出用于权限比较:

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

所以在我看来,我正在尝试使用本地用户通过 UNIX 套接字进行连接.我找到了一些描述这个问题的文章.当我通过 TCP/IP 连接时,这应该可以解决,只需将主机:本地主机"添加到我的 database.yml 文件即可.但是,这正是我所做的,所以我不知道如何进行

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

这里是我的 pg_hba.conf:

here my pg_hba.conf:

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

服务器上正在运行另一个应用程序,它可以工作.它具有与我相同的 database.yml 配置集.

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

推荐答案

可能是由于缺少用于测试环境的 username 语句.请参阅这个问题

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

这篇关于“致命:角色“根"不存在"运行 rake db:schema:load 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆