0

I've cloned a repository, and set up everything via a virtual machine loaded with Ubuntu and using RVM. Everything regarding Ruby on Rails was installed via RVM.

My issue is that, my Ubuntu login is different to the user that I assume the data base wants. Example, my Ubuntu login is Matt, but when I start rails server and load into the localhost:3000, it is saying this:

ActiveRecord::NoDatabaseError
FATAL: role "James" does not exist 

I understand this is a postgres error, but what should I do now to make this work? I've search through the previous StackOverflow answers and the methods just don't work.

Eg. I've changed

local   all             postgres                                peer

to

local   all             postgres                                trust

Or using psql -h localhost -U postgres or sudo -u postgres createuser -s $(whoami); createdb $(whoami) and again, it doesn't work. The first command asks for a password, which I can't figure out.

  • The password for `sudo -u postgres createuser -s $(whoami);` is whatever you want the password for the postgres role to be. But I would really name the default postgres account something different than your OS username like for example `pg_user`. The only reason you would want them to be the same is for a passwordless ident authentication. – max Oct 10 '18 at 21:16
  • This QA might help: https://stackoverflow.com/questions/12720967/how-to-change-postgresql-user-password – MrYoshiji Oct 10 '18 at 21:21
  • You'll want to look at your config/database.yml file. The problem probably isn't with Postgres, it's with your Rails configuration. By default, with no `user:` listed, Rails will attempt to connect with the name of the user that started the server. – Chris Hall Oct 11 '18 at 00:37

1 Answers1

1

You can change the user Rails uses to connect to PostgreSQL by editing <project_root>/config/database.yml (source).

Also, the reason your first psql command didn't work is -h localhost requires a host entry in pg_hba.conf, not local. You can omit the -h localhost for the local entry to take effect since the default is to connect via a local socket.

Dave Gray
  • 715
  • 5
  • 11
  • 1
    Where the rails gem is installed is not relevant to where his configuration files are. They would be relative to the project _using_ rails, not the gem itself. – Chris Hall Oct 11 '18 at 00:32