page:guides:gin:database connection

Connect Postgres for Gin

Summary

Database connection for a Gin app on Ample. Verified on Gin: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: CGO_ENABLED=0 go build -o app ./... then ./app on the ubuntu-24.04 template (go.sum committed for a reproducible build).

Prerequisites

Resource Requirements

Infrastructure Requirements

Workflow Steps

  1. Build and start

    Build: CGO_ENABLED=0 go build -o app ./... then ./app on the ubuntu-24.04 template (go.sum committed for a reproducible build); the server must bind 0.0.0.0 on PORT.

  2. 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.

  3. 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

Success Checks

Limitations

Cost Estimate

Evidence Summary

Kind: canary_run
Summary: Gin pattern fixture deployed on Ample (CGO_ENABLED=0 go build -o app ./... then ./app on the ubuntu-24.04 template (go.sum committed for a reproducible build)); 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-21T01:15:54Z Impl. Revision: 50dbac567d2c5cc8e55e6c748a646be0025d9cfb-dirty (CLI 0.1.21) Expires At: 2027-03-20T01:15:54Z Scope: checks: /p/relational-records, template: ubuntu-24.04

Formats