element-hq / element-hq/dendrite

Cannot connect to postgres DB listening on localhost.

Open
#3,378 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
965
Forks
101
PR merge metrics
No merged PRs in 30d

Description

*This issue was originally created by [**@barkyq**](https://github.com/barkyq) at .*

### Background information

- **Dendrite version or git SHA**: 0.13.7+46902e5
- **SQLite3 or Postgres?**: Postgres
- **Running in Docker?**: no
- **`go version`**: go version go1.22.2 linux/amd64
- **Client used (if applicable)**: N/A

### Description

- **What** is the problem: cannot connect to DB when postgres is listening on `127.0.0.1`
- **Who** is affected: cannot start server
- **How** is this bug manifesting: cannot start server
- **When** did this first appear: after updating

### Steps to reproduce

Default Postgres set-up listening on 127.0.0.1

in dendrite.yaml have the line

```
postgresql://dendrite:PASSWORD@127.0.0.1:5432/dendrite?sslmode=disable
```

and when I start the server with:

```
./bin/dendrite -config dendrite.yaml -http-bind-address 127.0.0.1:8008
```

it fails with the error:

```
PANI[2024-05-21T14:13:42.984256370Z] failed to connect to room server db error="sqlutil.Open: failed to find maximum conections: pq: no pg_hba.conf entry for host \"X.X.X.X\", user \"dendrite\", database \"dendrite\", SSL off"
```

where `X.X.X.X` is the public IP of my server (not `127.0.0.1`).

I was able to fix by manually editing postgres conf files. This was not necessary before.

```
sudo nano /etc/postgresql/13/main/postgresql.conf

change `listen_addresses = 'localhost'` to `listen_addresses = '*'`

sudo nano /etc/postgresql/13/main/pg_hba.conf

add line `host all all 0.0.0.0/0 md5`
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with dendrite.yaml, the PostgreSQL connection URL, and the shown ./bin/dendrite command; inspect how Dendrite opens its PostgreSQL connection and selects the connection host. Done means a PostgreSQL server listening on localhost can be used without manually broadening postgresql.conf or pg_hba.conf.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.