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

Document the URL syntax for Unix-domain sockets when connecting to postgres #3740

Open
IreneKnapp opened this issue Feb 14, 2025 · 1 comment
Labels
db:postgres Related to PostgreSQL documentation Improvements or additions to documentation

Comments

@IreneKnapp
Copy link

I have found these related issues/pull requests

I searched, but wasn't able to find any.

Description

The behavior implemented at https://docs.rs/sqlx-postgres/0.8.3/src/sqlx_postgres/options/parse.rs.html#13 is quite important to know about for anyone who relies on Unix-domain sockets. Somebody clearly wrote this feature deliberately, but the examples do not show how to construct a URL for a Unix-domain socket.

To save time in case whoever triages this doesn't have context for the code: What it does is it takes the hostname component of the URL, percent-decodes it, and if the percent-decoded string is non-empty and starts with a slash, it is used as a filesystem path pointing to a Unix-domain socket. Otherwise it's used as a DNS hostname.

This seems to have changed in a recent version; it caused a production outage for me today. It appears that the old default when the hostname is blank was to use a Unix-domain socket with the default path, and now it is to use a TCP socket to localhost.

So, for example, the old URL postgres:///lotsadata now needs to become postgres://%2frun%2fpostgresql%2f.s.PGSQL.5432/lotsadata. This is no big deal, as long as people know about it!

I'm not complaining, I'm glad that sqlx exists, but I thought you'd want to know that some of us do rely on these small details, including indirect reliance via downstream projects that have been supporting the old behavior without realizing it exists. It was quite the debugging marathon. A few words in the documentation could have helped the downstream projects to be aware of the subtlety and know to mention it in their own documentation...

[this is of course a feature request - asking for a documentation change - but I couldn't figure out how to fit the things I have to say into the feature request template, so I'm using the bug report template. sorry about that.]

Reproduction steps

Read the documentation at [1]. Observe that it does not mention Unix-domain sockets.

[1] https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgConnectOptions.html

SQLx version

0.8.3

Enabled SQLx features

N/A

Database server and version

Postgres

Operating system

NixOS

Rust version

N/A

@IreneKnapp IreneKnapp added the bug label Feb 14, 2025
@abonander abonander added documentation Improvements or additions to documentation db:postgres Related to PostgreSQL and removed bug labels Feb 14, 2025
@jaskij
Copy link

jaskij commented Feb 26, 2025

FWIW, I have a mildly complicated postgres URL using UDS, and just used the same one I used with tokio-postgres.

postgres:///database_name?user=user_name&host=/run/postgresql

I do agree that in general, documentation on this is somewhat difficult to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:postgres Related to PostgreSQL documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants