简体   繁体   English

Postgres Rails数据库错误

[英]Postgres Rails DB Bug

I have just created a new RoR project on a Godaddy VPS running Ubuntu. 我刚刚在运行Ubuntu的Godaddy VPS上创建了一个新的RoR项目。 The app is set up to run Postgres, which is installed and running. 该应用程序设置为运行Postgres,Postgres已安装并正在运行。

Wwhen I do the INITIAL rake, I get: 当我做INITIAL耙子时,我得到:

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

Here is my database yml 这是我的数据库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: ###

I have tried root and philip . 我已经尝试过rootphilip
And I have created roles and users in PG for both. 而且我已经在PG中创建了角色和用户。

In Ubuntu, PostgreSQL by default is configured to allow local connections over Unix socket only to authenticate with the same username as the connecting Unix user. 在Ubuntu中,默认情况下,PostgreSQL被配置为允许通过Unix套接字的本地连接仅使用与连接的Unix用户相同的用户名进行身份验证。

You are running your app as root in your OS. 您正在以操作系统的root身份运行应用程序。 And PostgreSQL forces you to use root as a database user name. PostgreSQL强制您使用root作为数据库用户名。 If you want it to use a different database account, you need to run your app as a different user. 如果希望它使用其他数据库帐户,则需要以其他用户身份运行应用程序。

Apparently, your PostgreSQL server doesn't have a root account. 显然,您的PostgreSQL服务器没有root帐户。

A dirty fix could be authentication over TCP/IP: set a host to 127.0.0.1 in your database.yml , and these restrictions won't have any effect. 肮脏的修补程序可能是通过TCP / IP进行的身份验证:在您的database.yml中将host设置为127.0.0.1 ,这些限制将无效。
Another way to circumvent it is to edit pg_hba.conf to not require "the same user" for local connections. 另一种规避它的方法是编辑pg_hba.conf以使本地连接不需要“同一用户”。

You need to create the roles and database by hand: 您需要手动创建角色和数据库:

SSH into the vps and then ... SSH进入vps,然后...

Switch into the default user: 切换到默认用户:

sudo su – postgres

Once logged in as this user, you can create the new role: 以该用户身份登录后,您可以创建新角色:

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

To outfit your user with a password, you can add the words –pwprompt to the createuser command: 要为用户配备密码,可以在createuser命令中添加单词–pwprompt:

createuser --pwprompt

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

I started over by deleting all roles in PG. 我首先删除了PG中的所有角色。 I recreated what I needed and it is all good 我重新创建了所需的东西,一切都很好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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