# Postgres connection error

**URL:** <https://travis-ci.community/t/postgres-connection-error/4778>\
**Category:** Linux\
**Created:** [August 18, 2019, 5:23pm UTC](https://travis-ci.community/t/postgres-connection-error/4778 "2019-08-18T17:23:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flenoir](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/flenoir/32/2556_2.png) [@flenoir](https://travis-ci.community/u/flenoir)\
**Post date:** [August 18, 2019, 5:23pm UTC](https://travis-ci.community/t/postgres-connection-error/4778/1 "2019-08-18T17:23:17Z")

</div>

Hi,

I’m deploying my app and i get an error related to postgres connection, error is 🙂

```auto
psycopg2.OperationalError: 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 5433?

```

before that, the Travis log says

```auto

/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/django/db/backends/postgresql/base.py:270: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.

```

as i’m using Pipenv i did create a .travis file like below 🙂

```auto
language: python
python:
  - '3.6.7'

# safelist
branches:
  only:
    - staging

services:
  - postgresql

env: DJANGO_SETTINGS_MODULE=purbeurre.settings.travis

before_install:
  - sudo service postgresql stop
  - sed -e 's/^port.*/port = 5433/' /etc/postgresql/10/main/postgresql.conf > postgresql.conf
  - sudo chown postgres postgresql.conf
  - sudo mv postgresql.conf /etc/postgresql/10/main
  - sudo service postgresql start 10

install:
  - make init
script:
  - make test

```

and the corresponding Makefile 🙂

```auto
help:
	@echo ' init'
	@echo ' install pipenv and all project dependencies'
	@echo ' test'
	@echo ' run all tests'

init:
	@echo 'Install python dependencies'
	pip install pipenv
	pipenv install

test:
	@echo 'Run all tests'
	pipenv run python manage.py test

```

Can you help understand this error and help me to fix it ?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [August 18, 2019, 8:54pm UTC](https://travis-ci.community/t/postgres-connection-error/4778/2 "2019-08-18T20:54:13Z")

</div>

Possible duplicate of

> [@Postgresql 11.2: Cannot connect](https://travis-ci.community/t/postgresql-11-2-cannot-connect/2680):
>
> I’m having trouble getting a build working with Postgresql 11.2. As with previous attempts, the [latest build](https://travis-ci.org/keithpitty/kpdotcom/builds/507439479?utm_source=github_status&utm_medium=notification) fails when an attempt is made to run a command via psql. Here’s the configuration: env: global: - CC\_TEST\_REPORTER\_ID=eca569d89e2a8d954a3e28ef958ce10e912eef6570bbdabbb28297e11948efa8 language: ruby before\_install: - gem update --system - gem install bundler rvm: - 2.6.2 services: - postgresql dist: - xenial addons: postgresql: "11.2" apt: packages: - postgr…

> [@Install Postgresql 11](https://travis-ci.community/t/install-postgresql-11/3894):
>
> Hello, I’ve been searching on the web for a proper way to install postgresql 11 without any success. Please can you help us ? I tried: addons: postgresql: '11' apt: packages: - postgresql-11 - postgresql-client-11 but the error is : Refused to start PostgreSQL 11, because PostgreSQL 9.2 is currently running! You should first stop 9.2 instance...
