【问题标题】:Postgres Rails DB BugPostgres Rails 数据库错误
【发布时间】:2014-10-24 11:00:48
【问题描述】:

我刚刚在运行 Ubuntu 的 Godaddy VPS 上创建了一个新的 RoR 项目。该应用程序设置为运行已安装并正在运行的 Postgres。

当我做 INITIAL rake 时,我得到:

server$ bin/rake db:create db:migrate
FATAL:  role "root" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.1.2/gems/activerecord-4.1.5/lib/active_record/........

这是我的数据库 yml

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username: philip
  password: ###    
test: &TEST
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username: philip
  password: ### - not real 

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username: philip
  password: ###

我已经尝试过rootphilip
我在 PG 中为两者创建了角色和用户。

【问题讨论】:

  • 不管我的database.yml如何,rake都会抱怨root
  • 我猜还有一个文件

标签: ruby-on-rails postgresql rake


【解决方案1】:

您需要手动创建角色和数据库:

SSH 进入 vps 然后...

切换到默认用户:

sudo su – postgres

以该用户身份登录后,您可以创建新角色:

createuser
Enter name of role to add: philip
Shall the new role be a superuser? (y/n) y

要为您的用户配备密码,您可以在 createuser 命令中添加单词 –pwprompt:

createuser --pwprompt

来源:https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-12-04

【讨论】:

  • 是的,奇怪的是它一直在说“root”。
【解决方案2】:

在 Ubuntu 中,PostgreSQL 默认配置为仅允许通过 Unix 套接字的本地连接使用与连接的 Unix 用户相同的用户名进行身份验证。

您在操作系统中以root 的身份运行您的应用程序。 PostgreSQL 强制你使用root 作为数据库用户名。如果您希望它使用不同的数据库帐户,则需要以不同的用户身份运行您的应用。

显然,您的 PostgreSQL 服务器没有root 帐户。

一个肮脏的修复可能是通过 TCP/IP 进行身份验证:在您的 database.yml 中将 host 设置为 127.0.0.1,这些限制不会产生任何影响。
绕过它的另一种方法是编辑pg_hba.conf 以不需要“同一用户”进行本地连接。

【讨论】:

    【解决方案3】:

    我通过删除 PG 中的所有角色重新开始。我重新创建了我需要的东西,一切都很好

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 1970-01-01
      • 2011-01-23
      • 2012-02-15
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      相关资源
      最近更新 更多