Getting StartedConnect your framework
Rails
Active Record with CapyDB. database.yml stays boring.
Environment
DATABASE_URL="postgres://user:password@host:6432/db?sslmode=require"
DATABASE_DIRECT_URL="postgres://user:password@host:5432/db?sslmode=require"database.yml
Rails reads DATABASE_URL automatically. A minimal explicit config:
production:
adapter: postgresql
url: <%= ENV["DATABASE_URL"] %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>Keep pool aligned with your thread count — Puma threads each take a connection, and the plan budget (15/30/60) is shared across all dynos/processes.
Migrations
db:migrate wants a direct connection:
DATABASE_URL="$DATABASE_DIRECT_URL" bin/rails db:migrateIf you separate concerns with Rails' multiple-database support, point a migration role at the direct URL and the primary at the pooled one.
Pitfalls
- Advisory locks: Rails uses them to serialize migrations; they do not work through transaction pooling. That is the concrete reason migrations need the direct URL (or set
advisory_locks: falseonly if you know there is exactly one migrator). prepared_statements: behind the pooled port, setprepared_statements: falseindatabase.ymlto avoidprepared statement already existserrors.sslmode: keepsslmode=requirein the URL; Rails passes it through to libpq.