Databases Best Practices
Rules for reliable schema evolution, pool sizing, and safe SQL in Rust services.
Busca en todas las páginas de la documentación
Rules for reliable schema evolution, pool sizing, and safe SQL in Rust services.
cargo sqlx prepare in CI.AppState. Never per request.instances × max_connections ≤ DB limit. Leave 20-30% headroom.acquire_timeout. Fail fast with 503 instead of hanging.ANY($1) batch loads.begin/commit.SELECT 1 on /ready only. Distinguish liveness from DB dependency.sqlx default for async services; ORM when relations dominate and team prefers builders.
Oversized pools exhausting PostgreSQL connections under load.
Acceptable for edge/single-tenant; PostgreSQL for multi-tenant SaaS.
Reports, bulk ingest, and performance-critical paths - keep in repository module.
testcontainers or #[sqlx::test] with disposable DB.
Separate pools; tolerate replication lag on dashboards.
Never - redact passwords in tracing subscribers.
Retry transactions; keep lock order consistent across code paths.
Port schema via sql migrations; rewrite queries incrementally.
Pool acquire time, query duration histograms, active connections gauge.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 16 jul 2026