Can't connect to Postgres database

My build is not connecting to my database, What would I have to change about my config file to get it working, I get the following error:
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” (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Cannot assign requested address Is the server running on host “localhost” (::1) and accepting TCP/IP connections on port 5432? Couldn’t create database for {“adapter”=>“postgresql”, “pool”=>5, “timeout”=>5000, “host”=>“localhost”, “port”=>5432, “password”=>nil, “database”=>“db/development”} rake aborted!

My Config.yaml file:

version: 2
jobs:
  build:
    environment:
      CC_TEST_REPORTER_ID: c4f52365b30f48c534efce208d179e780768b981bbaff44e9272bb704355dae8
    docker:
      # specify the version you desire here
       - image: circleci/ruby:2.5.1-node-browsers
      
      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "Gemfile.lock" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            bundle install --jobs=4 --retry=3 --path vendor/bundle
      - save_cache:
          paths:
            - ./vendor/bundle
          key: v1-dependencies-{{ checksum "Gemfile.lock" }}
        
      # Database setup
      - run: bundle exec rake db:create
      - run: bundle exec rake db:schema:load        

      # run tests!
      - run:
          name: run tests
          command: |
            mkdir /tmp/test-results
            TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
            
            bundle exec rspec --format progress \
                            --format RspecJunitFormatter \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \
                            $TEST_FILES
      # collect reports
      - store_test_results:
          path: /tmp/test-results
      - store_artifacts:
          path: /tmp/test-results
          destination: test-results

As far as I can tell, you do not have a database running. Where it says image: circleci/postgres:9.4 in your config, you need to uncomment that.

It’s also worth adding an extra run step to wait for the database listener to be ready before trying to connect.