#2781·sqlx

Unix socket URLs don't work with PostgreSQL

Author: edgaroghCreated Sep 25, 2023Updated Aug 21, 2026
Labelsbug

Bug Description

The bug seems to be the same as #1202 but it was marked as completed with a hack to bypass the defect instead of an actual fix.

I have a PostgreSQL server running locally with an account for my Unix username. According to the PostgreSQL specification, I should be able to connect to it using postgres:///my_database as a connection URL. But sqlx refuses to do that at compile-time and says error: empty host. The host definitely is empty, but that shouldn't be a problem.

Minimal Reproduction

.env:

DATABASE_URL=postgres:///database

Have a query! invocation in your Rust code, and it won't compile.

Temporary fix

Write the explicit URL-encoded path to the Unix socket as your hostname.

Info

  • SQLx version: 0.7.1
  • SQLx features enabled: ["postgres", "runtime-tokio"]
  • Database server and version: PostgreSQL 14
  • Operating system: Linux 5.15.0-84-generic
  • rustc --version: 1.72.0