Using a local database

Hi Aleph team, I am trying to connect a local postgres database by adding the ALEPH_DATABASE_URI.
ALEPH_DATABASE_URI= postgresql://aleph:password@localhost:5433/alephdb
OS: Ubuntu-sever 22.04.
Postgresql 14
The database is up and running on the same host. Looks like the container wasn’t able to connect to the 5433 port from the host.
After I run docker compose up -d I get this:

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at \"localhost\" (::1), port 5433 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?\nconnection to server at \"localhost\" (127.0.0.1), port 5433 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?\n\n(Background on this error at: https://sqlalche.me/e/20/e3q8 )"

For some reason, the UI cannot access local database on the same machine.
I didn’t find anything that could solve this. I know how to publish a port from the docker container to the localhost, but not viceversa.

Found this:
The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 10.0.
So I have to downgrade my local PostgreSQL to 10?

If you see that message it means you upgraded Aleph to (or past) the 3.15.3 release which upgraded the postgres version from 10 to 15. The release notes for that version contain a few hints at what can be done.

You have three options:

  • Downgrade postgres to version 10 in the docker-compose file(s)
  • Delete your postgres volume and restart with postgres 15
  • Migrate your postgres data to the format supported by version 15

Docker uses its own network of 172.x.x.x addresses. eg my aleph_worker_1 container is assigned the address 172.19.0.8. If I ask that to connect to localhost, its going to try to connect to itself. Localhost inside the container is not the same as localhost inside the host OS.
There are various suggestions around the internet about how to allow conections to the host OS. If the database on your host OS is bound to all IP addresses (probably a bad idea, but do-able if you undestand your firewalls), then you can ask the container to connect to the host OS public IP instead.
In my case, using the gateway IP seemed to work: 172.19.0.1
There are other suggestions around to use host.docker.internal and/or edit your docker compose file. That didn’t work for me. But anyway, I think you probably just need to keep trying different things until one sticks.