mealie icon indicating copy to clipboard operation
mealie copied to clipboard

[BUG] - Failure to connect to Postgres over a unix socket

Open anoadragon453 opened this issue 4 months ago • 0 comments

First Check

  • [X] This is not a feature request.
  • [X] I added a very descriptive title to this issue (title field is above this).
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the Mealie documentation, with the integrated search.
  • [X] I already read the docs and didn't find an answer.
  • [ ] This issue can be replicated on the demo site (https://demo.mealie.io/).

What is the issue you are experiencing?

I'm attempting to run mealie without using docker, and I'm trying to connect to my postgres database over a unix socket. To do so, I'm setting the following environment variables:

DB_ENGINE = "postgres";
POSTGRES_USER = "mealie";
POSTGRES_SERVER = "/run/postgresql";
POSTGRES_DB = "mealie";

When I start mealie, I find that it is attempting to connect with the wrong database name:

Mar 29 17:37:27 server init_db[2383102]: ERROR: 29-Mar-24 17:37:27         Error connecting to database: (psycopg2.OperationalError) connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "run/postgresql:5432/mealie" does not exist
Mar 29 17:37:27 server init_db[2383102]: (Background on this error at: https://sqlalche.me/e/20/e3q8)
Mar 29 17:37:27 server init_db[2383102]: ERROR: 29-Mar-24 17:37:27         Database connection failed. Retrying in 1 seconds...

My unix socket does indeed exist at /run/postgresql/.s.PGSQL.5432, however the database name "run/postgresql:5432/mealie" is not correct. It appears that this value isn't getting set correctly by the code, which I believe the relevant portion of is:

https://github.com/mealie-recipes/mealie/blob/79fb1fb2990ad5d102e54f0bc3b4f04c45b4ad1d/mealie/core/settings/db_providers.py#L36-L56

I also attempted to set POSTGRES_SERVER to /run/postgresql/.s.PGSQL.5432 instead, and ended up with:

Mar 30 01:15:31 plonkie init_db[2968013]: ERROR: 30-Mar-24 01:15:31         Error connecting to database: (psycopg2.OperationalError) connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "run/postgresql/.s.PGSQL.5432:5432/mealie" does not exist

...if that gives any hints as to how the DB name is being derived.

Steps to Reproduce

  1. Set up a postgres database with a database name, available over a unix socket.
  2. Specify the appropriate environment variables and start mealie.
  3. Observe that it fails to connect to the database.

Please provide relevant logs

See above.

Mealie Version

1.2.0

Deployment

Other (please specify below)

Additional Deployment Details

I'm using the NixOS mealie package, which just passes environment variables directly through without modification. Hence I believe this is an upstream bug, rather than one in the NixOS package.

anoadragon453 avatar Mar 30 '24 07:03 anoadragon453