#536·pghero

Support multiple databases via environment variables only, with no config file

Author: jrobison-opCreated Jun 5, 2026Updated Jun 9, 2026

The problem

When you want to run pghero with one single database, you can pull the existing ankane/pghero Docker image and inject a DATABASE_URL variable by way of your cloud platform (Amazon ECS task definition, etc). This is super easy because you don't need a build pipeline to build your own image, you don't need a git repository, etc. You just pull the image and run it with an environment variable.

But if you use multiple databases, then there's no support for the above pattern. You have to resort to one of the below two patterns, neither of which are very appealing:

  1. Build your own custom image with a custom config file, which usually means you need:
  • a git repository to hold the config file and the custom Dockerfile
  • a build pipeline to build the custom image
  • an image repository (ECR, etc)
  • multiple environment variables like DATABASE_URL_1, DATABASE_URL_2, etc, to provide the actual connection strings referenced in the config file
  1. Use a janky workaround where you override the ankane/pghero command and build the config file on the fly, then execute puma -C /app/config/puma.rb to start the service, like this:
bash
echo 'databases:'                             > /app/config/pghero.yml && \
echo '  main:'                               >> /app/config/pghero.yml && \
echo '    url: <%= ENV["DATABASE_URL_1"] %>' >> /app/config/pghero.yml && \
echo '  secondary:'                          >> /app/config/pghero.yml && \
echo '    url: <%= ENV["DATABASE_URL_2"] %>' >> /app/config/pghero.yml && \
puma -C /app/config/puma.rb

Proposed solution

The app should look for environment variables named DATABASE_URL_1, DATABASE_URL_2, DATABASE_URL_N and use those without requiring any config file.

Thanks.