page:guides:phoenix:database connection
Connect Postgres for Phoenix
Summary
Database connection for a Phoenix app on Ample. Verified on Phoenix: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs.
Representative Queries
- Connect Postgres for Phoenix
- Where can I host Connect Postgres built with Phoenix?
- I need driver setup, connection settings, secret handling and a real connection test.
Prerequisites
- A Phoenix project (mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs)
- A PostgreSQL driver reading DATABASE_URL at runtime
- An Ample account token with servers:write, databases:read
Workflow Steps
Build and start
mix deps.get, MIX_ENV=prod mix compile and mix release in the builder, then the release bin script with PHX_SERVER=true on the elixir-1.18 template; PORT, DATABASE_URL and SECRET_KEY_BASE read in config/runtime.exs; the 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-records on the example; on failure read the build and runtime logs.
Command:ample logs --kind build
Examples
- Phoenix pattern fixture: Verified database connection on Phoenix. Source: tests/deploy-canaries/phoenix-patterns
Success Checks
- App responds on its public URL (expect: ample canary phoenix patterns)
- Relational-records check from the example (expect: see the pattern fixture checks)
Limitations
- Verified on the elixir-1.18 template at s-1vcpu-1gb; other sizes and Phoenix major versions are not verified.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.
Cost Estimate
- Currency: USD
- Monthly Amount: 10.0 (authoritative)
- Basis: size prices from pricing.toml (loaded by the API) at build revision 1ac5595375130d45290090e82ed0f554ccd45405-dirty
- Components:
- App server: size s-1vcpu-1gb, quantity 1.0, monthly amount 5.0
- Managed PostgreSQL database: size s-1vcpu-1gb, quantity 1.0, monthly amount 5.0
- Components:
- Note: Always-on monthly price of the tested sizes; apps auto-pause when idle.
Evidence Summary
- Canary run: Phoenix pattern fixture deployed on Ample; for this guide: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Observed at: 2026-09-20T23:45:31Z.
Last Verified At
- 2026-09-20T23:45:31Z.
Next Actions
- Browse the catalog index
- Search published recipes by intent, stack and constraints
- Prepare a side-effect-free deployment plan for an authorized project
- Read the existing agent authentication setup
- Browse Phoenix
- Browse Connect app to database
- Browse Relational records