2

I'd like to setup postgresql for my rails app in Cloud9.

Although I followed the top voted answer of this post, the following error appeared when I tried to bundle exec rake db:create.

fe_sendauth: no password supplied
...
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "username"=>nil, "password"=>nil, "host"=>"0.0.0.0", "database"=>"app_development"}
fe_sendauth: no password supplied
...
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "username"=>nil, "password"=>nil, "host"=>"0.0.0.0", "database"=>"app_test"}

database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
  host:     <%= ENV['IP'] %>

development:
  <<: *default
  database: app_development

test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production

Gemfile

gem 'pg', '~> 0.18.2'

Although I found similar questions in stackoverflow, they doesn't work for me.

It would be appreciated if you could give me how to avoid this error.

Cloud 9 can't allow us to access to the pg_hba.conf file as this post mentioned.

EDIT!!!

host: localhost was added instead of host: <%= ENV['IP'] %> in "database.yml"

sudo vim /etc/postgresql/9.3/main/pg_hba.conf

# "local" is for Unix domain socket connections only
local   all             xxx                                     peer

instead of

# "local" is for Unix domain socket connections only
local   all             username                                     peer
Community
  • 1
  • 1
SamuraiBlue
  • 851
  • 2
  • 17
  • 44

1 Answers1

0

localhost as a host refers to a TCP connection

so in your database.yml

host:     localhost

and you use same username and password for all three environment check this as well.

or ENV['IP'] should be refer to localhost

check your auth method in pg_hba.conf it should be md5

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5

and if

# "local" is for Unix domain socket connections only
local   all             username                                  peer

then you'd need to connect through Unix domain sockets

if you are using a debian-like OS, that means putting /var/run/postgresql in the host field

so in database.yml

 host:  "/var/run/postgresql"

Hope it will solve your problem

Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • Thank you for your quick answer, @Rajarshi Das. `Cloud 9` can't allow us to access to the `pg_hba.conf` file as [this post](http://stackoverflow.com/questions/35329650/fe-sendauth-no-password-supplied-error-after-setting-up-postgresql-database-on) mentioned. It would be appreciated if you could give me any idea. – SamuraiBlue Apr 08 '16 at 12:40
  • @SamuraiBlue Cloud9 does not restrict access to that file, that's Linux doing it. You can edit it with `sudo vim /etc/postgresql/9.3/main/pg_hba.conf` – Brady Dowling Apr 08 '16 at 13:01
  • Thank you for your comment, @Brady Dowling. I can eidt `conf` file as you advised. But the same error is still displayed. – SamuraiBlue Apr 08 '16 at 14:00
  • did you check your username password and host at database.yml ? should not be same for all three environments – Rajarshi Das Apr 08 '16 at 14:02
  • Thank you for your comment, @Rajarshi Das. Although I changed username, password and host at database.yml, the following error appeared. `could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?` – SamuraiBlue Apr 09 '16 at 21:30
  • Not sure if I can help much more here but if you think this is related to Cloud9 you might find help by posting a topic at https://community.c9.io – Brady Dowling Apr 09 '16 at 22:45
  • Please add port in database.yml which is accuaring by your database postgresql – Rajarshi Das Apr 10 '16 at 03:16