page:guides:rails:database connection
Connect Postgres for Rails
Summary
Database connection for a Rails app on Ample. Verified on Rails: 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 rails server reading PORT on the ruby-3.4 template with RAILS_ENV=production.
Representative Queries
- Connect Postgres for Rails
- Where can I host Connect Postgres built with Rails?
- I need driver setup, connection settings, secret handling and a real connection test.
Resource Requirements
- primitive:compute
- primitive:postgres
Infrastructure Requirements
- Compute: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- 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.
Prerequisites
- A Rails project (bundle install into vendor/bundle from Gemfile.lock (development and test groups skipped), then Puma via
rails serverreading PORT on the ruby-3.4 template with RAILS_ENV=production) - 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 via
rails serverreading PORT on the ruby-3.4 template with RAILS_ENV=production; 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
Limitations
- Verified on the ruby-3.4 template at s-1vcpu-1gb; other sizes and Rails 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.
Success Checks
- App responds on its public URL: HTTP GET
/expects response: ample canary rails patterns - Relational-records check from the example: HTTP GET
/p/relational-recordsexpects to see the pattern fixture checks.
Cost Estimate
- Currency: USD
- Monthly Amount: 10.0
- Components:
- App server: s-1vcpu-1gb - 1.0 - $5.0/month
- Managed PostgreSQL database: s-1vcpu-1gb - 1.0 - $5.0/month
- Note: Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included.
Examples
- Rails pattern fixture: Verified database connection on Rails. Source: tests/deploy-canaries/rails-patterns.