CapyDB Docs
Getting StartedConnect your framework

Rails

Active Record with CapyDB. database.yml stays boring.

Environment

.env
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:

config/database.yml
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:migrate

If 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: false only if you know there is exactly one migrator).
  • prepared_statements: behind the pooled port, set prepared_statements: false in database.yml to avoid prepared statement already exists errors.
  • sslmode: keep sslmode=require in the URL; Rails passes it through to libpq.