简体   繁体   中英

Rails local server doesnt run : could not connect to server: Connection refused

My local server is not working anymore for my rails app. I get the following error message :

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?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?

I went to check my database logs. These are the last couple lines :

STATEMENT:  CREATE DATABASE starsetmetiers_development;
ERROR:  unrecognized configuration parameter "idle_in_transaction_session_timeout"
STATEMENT:  SET idle_in_transaction_session_timeout = 0;

ERROR:  unrecognized configuration parameter "row_security"
STATEMENT:  SET row_security = off;

FATAL:  database "stars_metiers_development" does not exist
FATAL:  database "stars_metiers_development" does not exist
LOG:  received smart shutdown request
LOG:  autovacuum launcher shutting down
LOG:  shutting down
LOG:  database system is shut down

I recently destroyed my dev database and recreated one by pulling the production one. I think it is rightly referenced in my database.yml file :

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

development:
  <<: *default
  database: starsetmetiers_development

I dont understand where this error comes from (I didnt find a postmaster.pid file in my postgres folder also). How can I fix this ?

I get this error message when I try to run rails c

/Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/irb/completion.rb:9:in `require': dlopen(/Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle
  Reason: image not found - /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/x86_64-darwin14.5.0/readline.bundle
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/2.0.0/irb/completion.rb:9:in `<top (required)>'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `require'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:128:in `require_command!'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:59:in `console'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /Users/davidgeismar/.rbenv/versions/2.0.0-p576/lib/ruby/gems/2.0.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
    from ./bin/rails:4:in `require'
    from ./bin/rails:4:in `<main>'

You're missing the readline dependency, as this line in your error output shows:

Library not loaded: /usr/local/opt/readline/lib/libreadline

You can fix this with

$ brew install readline

The parameter idle_in_transaction_session_timeout is new in 9.6 - I think you're trying to upload a 9.6 backup into an earlier version of Postgres.

I commented out the top of the dump as follows and got it working when I was having a problem. You might want to update Postgres when you get the chance.

SET statement_timeout = 0;
SET lock_timeout = 0;
-- SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
-- SET row_security = off;

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?

The cause of above error is your postgresql server is not running. So please run that as per your OS as below:

Ubuntu: sudo service postgresql start
Fedora: systemctl start postgresql
Windows: net start postgresql-9.xx

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