Skip to content

Phoenix (Elixir)

Tested with: Phoenix 1.7 · Ecto 3.12 · Postgrex 0.19 · MyXQL 0.7 · Elixir 1.17 / OTP 27

config/runtime.exs
config :my_app, MyApp.Repo,
hostname: "pg-7f3k.us-east.databasezy.com",
port: 5432,
database: "app",
username: "app",
password: System.fetch_env!("ZB_PASSWORD"),
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
ssl: [
verify: :verify_peer,
cacertfile: System.get_env("ZB_CA") || "databasezy-ca.pem",
server_name_indication: ~c"pg-7f3k.us-east.databasezy.com",
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]
]
lib/my_app/release.ex
defmodule MyApp.Release do
@app :my_app
def migrate do
Application.ensure_all_started(:ssl)
for repo <- Application.fetch_env!(@app, :ecto_repos) do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
end

bin/my_app eval "MyApp.Release.migrate" in the release step (Fly release_command, a Kubernetes Job).

  • Postgrex supports the pooled endpoint; disable prepared-statement caching with prepare: :unnamed when using it.
  • pool_size is per node; keep nodes × pool_size under the size’s max_connections.
  • Phoenix PubSub and Oban can use Postgres directly; for Valkey-backed PubSub use phoenix_pubsub_redis with a rediss:// URL and ssl: true.