Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for socket connection to PostgreSQL #4249

Open
1 task done
onovy opened this issue Oct 9, 2024 · 3 comments · May be fixed by #4456
Open
1 task done

Add support for socket connection to PostgreSQL #4249

onovy opened this issue Oct 9, 2024 · 3 comments · May be fixed by #4456
Labels
docker Pull requests that update Docker code enhancement New feature or request

Comments

@onovy
Copy link

onovy commented Oct 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Currently it's possible to connect to DB only over IP, but PostgreSQL supports Unix-domain socket connection. Can you add support to TeslaMate code + docker and Grafana docker please?

Probably best way to support this is to migrate to connection strings instead of host+port pair in envs.

Thanks.

Expected Behavior

No response

Steps To Reproduce

No response

Relevant log output

not relevant

Screenshots

No response

Additional data

No response

Type of installation

Docker

Version

1.30.1

@JakobLichterfeld JakobLichterfeld added docker Pull requests that update Docker code enhancement New feature or request labels Oct 9, 2024
@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Oct 9, 2024

Thanks for your suggestion.

Do you mean similar to using a reverse Proxy with Unix Domain Sockets with TeslaMate?

Btw. PR always welcome!

@brianmay
Copy link
Collaborator

brianmay commented Oct 9, 2024

If I am not mistaken I have come across this exact same issue.

He wants Teslamate to connect to postgresql using the socket, in my case that is /run/postgresql/.s.PGSQL.5432.

This results in less overheads (not sure how significant this is), and means we don't need to manage secrets for teslamate (because the database can do authentication based on the Unix user).

Ecto supports connecting via a socket. But unfortunately, AFAIK, ecto does not support connecting to a socket using a URL to the database. Which is unfortunate, it would mean we just need to support a URL and can connect anywhere. Rather the config needs :socket and :socket_dir values.

See elixir-ecto/postgrex#415

Note: need to check this is still correct. It is possible issue was fixed, but but bug report was not updated.

When I setup my new database I ended up using sockets where possible, and TCP using password authentication for the apps where this did not appear to be easy. Currently all my Elixir apps fall into this category.

@onovy
Copy link
Author

onovy commented Oct 10, 2024

Do you mean similar to using a reverse Proxy with Unix Domain Sockets with TeslaMate?

nope, that's different think. brianmay explained it exactly :)

My problem is not overhead nor secrets problem. I have PostgreSQL running on bare-metal, outside of docker. And in this setup it's much simpler to "mount" PostgreSQL socket into docker container instead of playing with TCP/IP.

Details:

  • psql needs to bind to IP, "*" is not secure
  • psql needs to bind to gateway IP (which is host itself) of docker bridge network to be accessible from docker container
  • docker bridge network is dynamic, it can be recreated with different subnets/IPs
  • I can setup static IPs, but that's anti-pattern for docker
  • psql can't bind to non-existent IP
  • bridge network interface with IPs is created dynamicaly, thus i need to start psql after dockerd

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Pull requests that update Docker code enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants