I am trying to get my Rails environment up and running with a Postgres database using AWS Cloud9 and have run into a problem when trying run rails db:migrate
.
Initially I created the project by running:
- rails new app_name -d postgresql
- bundle install
Bundler had a problem finding gem 'pg'
so I ran:
- sudo yum install postgresql-devel
- sudo yum install postgresql-server
- sudo postgresql initdb
- sudo service postgresql start
The server fired up fine afterwards and I thought all was well until running rails db:migrate
which returned the error:
PG::ConnectionBad: FATAL: role "ec2-user" does not exist
I am unsure how to fix this.
It has been suggested that I may need to get into my psql shell and alter or create a new role, but I'm unsure how to alter the ec2-user
.
It has also been suggested that my pg_hba.conf
file may need some alterations. I have the path to that file, but am not sure how to edit it or if that's something that I really want to do.
Any suggestions? I'm including my database.yml
below:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: my_app_development
test:
<<: *default
database: my_app_test
production:
<<: *default
database: my_app_production
username: my_app
password: <%= ENV['MY_APP_DATABASE_PASSWORD'] %>
ec2-user
. You are executing therails db:migrate
command as that user. PG cannot find that user in the DB. I believe you can create that user in the DB as you started hereIt has been suggested that I may need to get into my psql shell and alter or create a new role
or I believe you can create a new linux user that matches the username in the DB. If I could recall the exact steps, I would have posted the answer, but I cannot remember them. – Razidsudo -u postgres createuser -s ec2-user
. – Razidcreateuser: creation of new role failed: ERROR: role "ec2-user" already exists
I wonder what the conflict is. – Endurerake db:migrate RAILS_ENV=production
– Razidrake db:migrate RAILS_ENV=development
and the migration went through successfully. BUT when I runrake db:migrate RAILS_ENV=production
i get a peer authentication error. I think that I might just need to create a user/role forveggie_app
. Thanks again for your help. I can hopefully figure it out from here.... maybe. At least everything is working fine in development : ) – Enduredatabase.yml
file. I removed those for now and all is well. – Enduresudo service postgresql initdb
– Sarraute