0

I have just created a new RoR project on a Godaddy VPS running Ubuntu. The app is set up to run Postgres, which is installed and running.

Wwhen I do the INITIAL rake, I get:

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

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.
And I have created roles and users in PG for both.

2
  • Regardless of my database.yml, rake complains about root Commented Aug 30, 2014 at 17:40
  • I guess there is another file Commented Aug 30, 2014 at 17:40

3 Answers 3

1

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.

You are running your app as root in your OS. And PostgreSQL forces you to use root as a database user name. 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.

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.
Another way to circumvent it is to edit pg_hba.conf to not require "the same user" for local connections.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to create the roles and database by hand:

SSH into the vps and then ...

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

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

1 Comment

Yeah that's strange that it keeps saying "root".
0

I started over by deleting all roles in PG. I recreated what I needed and it is all good

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.