0

I am following this guide to set up a rails project with Postgres.

So far I have installed postgress and the Heroku toolbelt and done the following:

  1. Logged in using my heroku credentials
  2. Created a rails project using postgres rails new myapp --database=postgresq
  3. The default database.yml file looks like this:

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
    
    development:
      <<: *default
      database: myapp_development
    
    test:
      <<: *default
      database: myapp_test
    
    production:
      <<: *default
      database: myapp_production
      username: myapp
      password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
    
  4. created controller for homepage rails g controller welcome

  5. Created index.html.erb and added routing. root 'welcome#index'

Then When I run the server, go to localhost:3000 and get the following error PG::ConnectionBad (fe_sendauth: no password supplied):

Is the issue with the database.yml file or with the installation and setup of postgres?

test
  • 3
  • 3
  • Seems like this `<%= ENV['MYAPP_DATABASE_PASSWORD'] %>` is `nil`. Are you sure you have the *EVN variables* in Heroku? – Pavan Jun 09 '17 at 10:51
  • @pavan I don't think so, I will look into it. Thanks for the comment – test Jun 09 '17 at 11:10
  • I think it's issue with postgres config. Check out my answer for this question to solve it https://stackoverflow.com/questions/13690162/rails-postgres-fe-sendauth-no-password-supplied/13690394#13690394 – Thanh Jun 11 '17 at 10:05

3 Answers3

2

In config/database.yml, under default: &default, add:

 host: localhost
 username: postgres
 password: (the password you created during postgresql installation goes here)
 port: 5432

Then in your terminator run rake db:create:all(don't worry if you encountered the same problem here) and then run rake db:migrate, restart your rails server and your app should now work.

P.S. I've noticed that this question was asked over a year ago and that you already figured out a solution back then. But I am putting this solution here for anyone who might face the same problem because I encountered this problem two days ago and it took me some time to figure out a solution that worked for me.

Hajar
  • 157
  • 1
  • 4
  • 16
  • This solution worked. Any pointers as to why setting these are important? I recently moved to a Windows platform. Had a hard time configuring a project clone. The project was setup in ubuntu. Found no issues there. – arjun Nov 15 '18 at 14:17
  • @arjun I am glad it worked for you, too. But to be honest, I don't know why setting these are important. Sorry. – Hajar Nov 15 '18 at 19:43
0

figured it out. All I had to to was open pgAdmin and login using the password I created during installation.

test
  • 3
  • 3
0

Add username and password to default

default: &default
      adapter: postgresql
      encoding: unicode
      # For details on connection pooling, see Rails configuration guide
      # https://guides.rubyonrails.org/configuring.html#database-pooling
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
      username: postgres
      password: postgres
Ruan Nawe
  • 363
  • 6
  • 9