# 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
1. **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; 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.  
`ample logs --kind build`

## Success Checks
- **app responds on its public URL**  
  - Kind: `http_get`  
  - Path: `/`  
  - Expect: `ample canary sinatra patterns`
- **relational-records check from the example**  
  - Kind: `http_get`  
  - Path: `/p/relational-records`  
  - Expect: `see the pattern fixture checks`

## 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
- **managed PostgreSQL database**  
  - Size: `s-1vcpu-1gb`  
  - Quantity: 1.0  
  - Monthly Amount: 5.0

## 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

## Formats
- **HTML**: [Link](/content/guides/sinatra/database-connection/index.html)
- **Markdown**: [Link](/content/guides/sinatra/database-connection.md)
- **JSON**: [Link](https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Asinatra%3Adatabase-connection)
