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:
Bundler had a problem finding gem 'pg'
so I ran:
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'] %>
Every user of psql
also needs a corresponding database that matches their name.
At the bash command line:
sudo -u postgres createuser -s ec2-user
sudo -u postgres createdb ec2-user
The above should allow your user to access psql
, but it won't let rails make migrations yet. You'll have to do the following first:
sudo su postgres
psql
ALTER USER "ec2-user" WITH SUPERUSER;
\q
exit
I put that together quite quickly so let me know if you run into any problems.
If your config/database.yml
is using a different login user to your bash user, you should repeat all above steps for that user as well.
Lastly, although you are on Cloud9, this is just a simple Rails/Postgres issue, rather than an AWS issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With