page:guides:axum:database connection
Connect Postgres for Axum
Summary
Database connection for an Axum app on Ample. Verified on Axum: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start using the following command:
cargo build --release
This should be run in the Rust builder image (stable toolchain, Cargo.lock committed, pure-Rust dependencies), then the release binary on the ubuntu-24.04 template reading PORT and DATABASE_URL.
Prerequisites
- A Axum project (use
cargo build --releasein the rust builder image) - A PostgreSQL driver reading DATABASE_URL at runtime
- An Ample account token with
servers:write,databases:readpermissions
Resource Requirements
- Compute: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request.
- Postgres: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.
Workload
Steps to Connect Postgres
Build and start:
cargo build --releaseThe server must bind 0.0.0.0 on PORT.
Read DATABASE_URL at runtime: Open connections from the environment inside handlers or a pool; omit DATABASE_URL to auto-provision a managed database or pass
--env DATABASE_URL=...for an existing one.Verify: Fetch the live URL and
/p/relational-recordson the example; on failure read the build and runtime logs.ample logs --kind build
Limitations
- Verified on the ubuntu-24.04 template at s-1vcpu-2gb; other sizes and Axum major versions are not verified.
- Region and compliance attestations and request-duration limits are unknown.
- Managed PostgreSQL 16 only; extensions, connection limits, and backup or restore procedures are not verified.
Cost Estimate
- Monthly Amount: $10.00
- Components:
- App server: s-1vcpu-1gb, 1.0, $5.00
- Managed PostgreSQL database: s-1vcpu-1gb, 1.0, $5.00
Note: Always-on monthly price of the tested sizes; apps auto-pause when idle.
Success Checks
- App responds on its public URL
- Relational records check from the example
Evidence Summary
- Axum pattern fixture deployed on Ample, with a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time.
Next Actions
- Browse the catalog index: API Catalog
- Search published recipes: Search Recipes