Skip to content

Conversation

Fijxu
Copy link
Member

@Fijxu Fijxu commented Jun 12, 2025

Currently only database_url shows how to connect via unix sockets. This adds some docs for db too

@syeopite syeopite added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label Jun 15, 2025
@Fijxu
Copy link
Member Author

Fijxu commented Jun 15, 2025

Note: When using config.db, Invidious will only search for this list of paths on the filesystem: https://github.com/will/crystal-pg/blob/cafe112f2847f366262460ee999e74f9c7e8b31c/src/pq/conninfo.cr#L7

It will not consider PostgreSQL installations running on another port like 5433 (this will make PostgreSQL create a unix socket called .s.PGSQL.5433 and not .s.PGSQL.5432), so it will fail to connect. This can cause some annoyances on PostgreSQL cluster installations where you can run more than one PostgreSQL version and server on different ports (how Debian seems to handle it: https://wiki.debian.org/PostgreSql#Listing_existing_database_clusters).

This is not a problem when using database_url since you can pass a custom unix socket path using the host query parameter like this:

database_url: postgres://kemal:kemal@/invidious?host=/var/run/postgresql/.s.PGSQL.5433

Maybe we can add an option to point to a socket path on db 🤔?

@SamantazFox
Copy link
Member

Note: When using config.db, Invidious will only search for this list of paths on the filesystem: https://github.com/will/crystal-pg/blob/cafe112f2847f366262460ee999e74f9c7e8b31c/src/pq/conninfo.cr#L7

It will not consider PostgreSQL installations running on another port like 5433 (this will make PostgreSQL create a unix socket called .s.PGSQL.5433 and not .s.PGSQL.5432), so it will fail to connect.

This is the preconfigured fallback. If you pass a host, it will use that instead:
https://github.com/will/crystal-pg/blob/cafe112f2847f366262460ee999e74f9c7e8b31c/src/pq/conninfo.cr#L125

Then, if the host starts with a /, the PG driver will open a unix socket:
https://github.com/will/crystal-pg/blob/cafe112f2847f366262460ee999e74f9c7e8b31c/src/pq/connection.cr#L25-L26

I think that all we need to do is adapt our code to not build a postgres:// URI if we see a host starting with /.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants