← Writing

Using Neon serverless Postgres with SQLx

2026-06-10#postgres#neon#sqlx#rust

Why Neon?

Neon gives you a real Postgres instance that scales to zero when idle — perfect for a personal site that gets bursty traffic. The connection string is standard Postgres so SQLx works without any special drivers.

Gotcha: channel_binding

Neon requires ?sslmode=require&channel_binding=require in the connection string. Without channel_binding=require you'll get confusing TLS handshake errors.

Migrations

SQLx's sqlx migrate run works perfectly against Neon. I run it as part of the Docker entrypoint so migrations apply automatically on every deploy.

Connection pooling

I use a OnceLock<PgPool> initialized lazily on the first request. Neon's serverless model means the compute can spin down between requests, but the pool handles reconnects transparently.