page:guides:sinatra:database connection
Connect Postgres for Sinatra
Summary
Database connection for a Sinatra app on Ample. Verified on Sinatra: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma via rackup (config.ru) reading PORT on the ruby-3.4 template.
Prerequisites
- A Sinatra project (bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma via
rackup(config.ru) reading PORT on the ruby-3.4 template) - A PostgreSQL driver reading DATABASE_URL at runtime
- An Ample account token with servers:write, databases:read
Workflow Steps
Build and start
bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma viarackup(config.ru) reading PORT on the ruby-3.4 template; 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.ample logs --kind build
Success Checks
- app responds on its public URL
- Kind:
http_get - Path:
/ - Expect:
ample canary sinatra patterns
- Kind:
- relational-records check from the example
- Kind:
http_get - Path:
/p/relational-records - Expect:
see the pattern fixture checks
- Kind:
Limitations
- Verified on the ruby-3.4 template at s-1vcpu-1gb; other sizes and Sinatra 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
- 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
- Size:
- managed PostgreSQL database
- Size:
s-1vcpu-1gb - Quantity: 1.0
- Monthly Amount: 5.0
- Size:
Evidence Summary
- Kind: canary_run
- Summary: Sinatra pattern fixture deployed on Ample (bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma via
rackup(config.ru) reading PORT on the ruby-3.4 template); 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
- Summary: Sinatra pattern fixture deployed on Ample (bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma via