Search code examples
ruby-on-railsrubyrubygemsconsul

rake aborted! PG::ConnectionBad: could not connect to server: Connection refused


I've been trying to install the Consul software for a few hours. For this I use the installation instructions https://docs.consulproject.org/docs/english-documentation/introduction/local_installation

Unfortunately, I have virtually no idea about Ruby, Postgres, etc.

Unfortunately, I get an error message when I run the following commands.

rake db: create
rake db: setup
rake db: dev_seed
rake db: test: prepare

Here is the entire issue:

rake db:create
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/definition.rb:31: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/decorator.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/sum.rb:43: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/dry-types-0.13.3/lib/dry/types/options.rb:8: warning: The called method `initialize' is defined here
warning: parser/current is loading parser/ruby27, which recognizes
warning: 2.7.2-compliant syntax, but you are running 2.7.0.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/type.rb:27: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/type/adapter_specific_registry.rb:9: warning: The called method `add_modifier' is defined here
/var/lib/gems/2.7.0/gems/acts-as-taggable-on-6.5.0/lib/acts_as_taggable_on/tagging.rb:9: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/associations.rb:1653: warning: The called method `belongs_to' is defined here
/var/lib/gems/2.7.0/gems/actionpack-5.2.4.4/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/var/lib/gems/2.7.0/gems/actionpack-5.2.4.4/lib/action_dispatch/middleware/static.rb:111: warning: The called method `initialize' is defined here
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?
Couldn't create 'consul_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: 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?
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `initialize'
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `new'
/var/lib/gems/2.7.0/gems/pg-1.0.0/lib/pg.rb:56:in `connect'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/connection_handling.rb:90:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:119:in `create'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/var/lib/gems/2.7.0/gems/activerecord-5.2.4.4/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.7.0/gems/airbrake-5.8.1/lib/airbrake/rake/task_ext.rb:19:in `execute'
/usr/share/rubygems-integration/all/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `load'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:74:in `kernel_load'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli/exec.rb:28:in `run'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:463:in `exec'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:27:in `dispatch'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/cli.rb:18:in `start'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/exe/bundle:30:in `block in <top (required)>'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
/var/lib/gems/2.7.0/gems/bundler-1.17.1/exe/bundle:22:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

Does anyone have any idea how to solve this? Thanks in advance!


Solution

  • This means that Postgresql isn't running so it cannot make the database.

    Have you installed Postgres? If so, you can likely start the service by using:

    sudo service postgresql restart
    

    If Postgres isn't installed, you first need to install it. How to do so differs depending on your system:
    https://www.postgresqltutorial.com/install-postgresql/