# Issues with connecting postgres (localhost) with latest odk central (v 2023.2)

**URL:** <https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568>\
**Category:** Support\
**Created:** [May 17, 2023, 4:14am UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568 "2023-05-17T04:14:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arunbala](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/arunbala/32/18406_2.png) [@Arunbala](https://forum.getodk.org/u/Arunbala)\
**Post date:** [May 17, 2023, 4:14am UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/1 "2023-05-17T04:14:26Z")

</div>

I tried to install ODK latest version in my local Ubuntu machine but it has some issues to connect with my local PostgreSQL db. it is running on port 5432 and i have turned off firewall.

central-service-1 Error: connect ECONNREFUSED 127.0.0.1:5432

**My env**

DOMAIN=local  
[SYSADMIN\_EMAIL=administrator@email.com](mailto:SYSADMIN_EMAIL=administrator@email.com)  
SSL\_TYPE=selfsign  
HTTP\_PORT=81  
HTTPS\_PORT=443

**Optional: connect to a custom database server**  
DB\_HOST=localhost  
DB\_USER=postgres  
DB\_PASSWORD=\*\*\*\*  
DB\_NAME=mydbname

I followed all the steps given in the docs .will it connect with local PostgreSQL db , what am i doing wrong?

 ![Screenshot from 2023-05-17 09-40-45](https://getodk.b-cdn.net/uploads/default/original/3X/5/e/5e7f44cb7a5c9705e0d89b8ce54a36eccca88289.png)

**Dockered version of postgres has this error**

central-service-1 exited with code 1  
central-postgres14-1 | 2023-05-17 05:46:14.379 UTC [55] LOG: incomplete startup packet  
central-postgres14-1 | 2023-05-17 05:46:14.649 UTC [56] FATAL: password authentication failed for user "odk"  
central-postgres14-1 | 2023-05-17 05:46:14.649 UTC [56] DETAIL: Connection matched pg\_hba.conf line 100: "host all all all scram-sha-256"  
central-service-1 | Error: password authentication failed for user "odk"  
central-service-1 | checking migration success..

---

<div class="post-metadata">

**Author:** ![A.N.M\_AL-IMRAN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/a.n.m_al-imran/32/1610_2.png) [@A.N.M\_AL-IMRAN](https://forum.getodk.org/u/A.N.M_AL-IMRAN)\
**Post date:** [May 18, 2023, 2:01pm UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/2 "2023-05-18T14:01:00Z")

</div>

What is the local Ubuntu version?

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [May 18, 2023, 4:34pm UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/3 "2023-05-18T16:34:15Z")

</div>

`DB_HOST` needs to be the IP or hostname of the database from the perspective of the service container. When you put localhost, the service container is trying to connect to itself.

I haven't tried this myself, but according to [https://stackoverflow.com/questions/24319662](https://stackoverflow.com/questions/24319662), if you use `host.docker.internal` as the `DB_HOST` and the following to your compose file, it should work.

```auto
extra_hosts:
    - "host.docker.internal:host-gateway"

```

---

<div class="post-metadata">

**Author:** ![Arunbala](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/arunbala/32/18406_2.png) [@Arunbala](https://forum.getodk.org/u/Arunbala)\
**Post date:** [May 19, 2023, 4:42am UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/4 "2023-05-19T04:42:24Z")

</div>

I am using Ubuntu 22.04.2 LTS.

---

<div class="post-metadata">

**Author:** ![Arunbala](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/arunbala/32/18406_2.png) [@Arunbala](https://forum.getodk.org/u/Arunbala)\
**Post date:** [May 19, 2023, 10:04am UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/5 "2023-05-19T10:04:12Z")

</div>

Hi @yanokwa , thanks it worked , but i have to add changes in my **pg\_hba conf**  
`host all biodiv 0.0.0.0/0 md5` because i got an error

```auto
central-service-1 exited with code 1
central-service-1 | wait-for-it.sh: host.docker.internal:5432 is available after 0 seconds
central-service-1 | generating local service configuration..
central-service-1 | running migrations..
central-service-1 | Error: no pg_hba.conf entry for host "172.24.0.5", user "biodiv", database "mydbname", no encryption
central-service-1 | checking migration success..
central-service-1 | Error: no pg_hba.conf entry for host "172.24.0.5", user "biodiv", database "mydbname", no encryption
central-service-1 | ***Error starting ODK!***
central-service-1 | After attempting to automatically migrate the database, we have detected unapplied migrations, which suggests a problem with the database migration step. Please look in the console above this message for any errors and post what you find in the forum: https://forum.getodk.org/

```

and this change `listen_addresses ='*'` in **postgresql.conf** without it i have this error

```auto
central-service-1 exited with code 0
central-service-1 | wait-for-it.sh: timeout occurred after waiting 15 seconds for host.docker.internal:5432
central-service-1 | generating local service configuration..
central-service-1 | running migrations..
central-service-1 | Error: connect ECONNREFUSED 172.17.0.1:5432
central-service-1 | checking migration success..
central-service-1 | Error: connect ECONNREFUSED 172.17.0.1:5432
central-service-1 | ***Error starting ODK!***
central-service-1 | After attempting to automatically migrate the database, we have detected unapplied migrations, which suggests a problem with the database migration step. Please look in the console above this message for any errors and post what you find in the forum: https://forum.getodk.org/
central-service-1 exited with code 0

```

its IP (172.24.0.5) keeps on changing when i stopped and ran it again. is this a concern , any other way can i overcome these changes?

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [May 19, 2023, 4:07pm UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/6 "2023-05-19T16:07:04Z")

</div>

The changes you've made so far seem expected.

I'd be cautious about `listen_addresses`. [https://www.digitalocean.com/community/tutorials/how-to-secure-postgresql-against-automated-attacks](https://www.digitalocean.com/community/tutorials/how-to-secure-postgresql-against-automated-attacks) has more guidance on that. The most important thing here is to make sure your database isn't accessible outside of your local machine.

The `172.x.x.x` IP range is usually from Docker. Not sure how to work around that. Either way, it's outside the scope of the support we can provide on ODK.

---

<div class="post-metadata">

**Author:** ![Arunbala](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/arunbala/32/18406_2.png) [@Arunbala](https://forum.getodk.org/u/Arunbala)\
**Post date:** [May 24, 2023, 4:34am UTC](https://forum.getodk.org/t/issues-with-connecting-postgres-localhost-with-latest-odk-central-v-2023-2/41568/7 "2023-05-24T04:34:45Z")

</div>

Hi @yanokwa, I have discovered an alternative method for connecting ODK Central to localhost Postgres. Here are the modifications I made:

**Environment variable changes:**

```auto
DB_HOST=192.X.X.X
DB_USER=odk
DB_PASSWORD=XXXX
DB_NAME=odk

```

**Modifications in postgresql.conf:**  
`listen_addresses ='localhost,192.X.X.X'`

**Modifications in pg\_hba.conf:**  
`host all all 172.0.0.0/8 md5`

These adjustments have proven to be effective, and thanks for the support.
