简体   繁体   中英

postgresql error in Cloud9 “could not connect to server: Connection refused”

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

The following error appeared when I tried to bundle exec rake db:create .

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?
...

database.yml

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

development:
  <<: *default
  database: app_development

test:
  <<: *default
  database: app_test

production:
  <<: *default
  database: app_production

Gemfile

gem 'pg', '~> 0.18.2'

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

# Database administrative login by Unix domain socket
local   localhost            ubuntu                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             ubuntu                                    md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

Although I found similar questions in stackoverflow, they don't work for me. It would be appreciated if you could advise me on how to avoid this error.

Configure the postgresql.conf file. You have to update the listen_addresses to all and make sure to uncomment that line by removing the # mark. So your listen_addresses should look like this listen_addresses = '*'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM