2026-01-14
·
rails
deployment
Rails Multiple Databases with Environment Variables
When deploying Rails with multiple databases (Solid Cable, Solid Cache, Solid Queue), you can configure each database using prefixed environment variables.
The naming convention is {DATABASE_NAME}_DATABASE_URL:
# config/database.yml
production:
primary:
url: <%= ENV["DATABASE_URL"] %>
cache:
url: <%= ENV["CACHE_DATABASE_URL"] %>
cable:
url: <%= ENV["CABLE_DATABASE_URL"] %>
queue:
url: <%= ENV["QUEUE_DATABASE_URL"] %>
Then set the corresponding environment variables:
DATABASE_URL=postgres://user:pass@host/myapp_production
CACHE_DATABASE_URL=postgres://user:pass@host/myapp_cache
CABLE_DATABASE_URL=postgres://user:pass@host/myapp_cable
QUEUE_DATABASE_URL=postgres://user:pass@host/myapp_queue
This keeps credentials out of your repo. It also lets each database live on its own host, or even a different engine entirely, like SQLite for cache while primary stays on Postgres.