Hi everyone,
I’m running a Phoenix app with a managed Postgres cluster, and I keep hitting recurring connection errors like these:
[error] Postgrex.Protocol (#PID<0.2115.0>) failed to connect:
** (Postgrex.Error) FATAL 08P01 (protocol_violation) server login has been failing, cached error: server conn crashed? (server_login_retry)
[error] Postgrex.Protocol (#PID<0.2115.0>) disconnected:
** (DBConnection.ConnectionError) tcp recv (idle): timeout
At first I thought this was an app-side issue, but now I see that Fly.io Postgres uses PgBouncer by default for connection pooling. From what I’ve read in the Postgrex docs, this can conflict with named prepared statements unless I explicitly set prepare: :unnamed.
Questions:
- Are there any recommended Ecto/Postgrex settings when using Fly’s PgBouncer (timeouts, pool sizes, etc.)?
- Could the errors I’m seeing be directly related to PgBouncer (e.g. transaction pooling vs session pooling)? BTW I saw this section in the docs Configuring Connection Pool Mode but I wasn’t able to find those links in the dashboard.
For context:
-
DB is on the Basic plan (1GB RAM, shared CPU).
-
I’m running a mix of web + background jobs (Oban) - very light ( just a POC for my company to migrate from AWS to Fly)
-
App is just 1 machine for now, and I have one repo for oban and one for api so it shouldn’t be hitting pool limits or connection limits.
Here’s my ecto repo config:
maybe_ipv6 = if System.get_env("ECTO_IPV6") in ~w(true 1), do: [:inet6], else: []
config :data_pipeline_cron_poc, DataPipelineCron.Repo,
url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "12"),
timeout: 15000,
socket_options: maybe_ipv6,
stacktrace: true,
prepare: :unnamed
config :data_pipeline_cron_poc, DataPipelineCron.ObanRepo,
url: database_url,
pool_size: String.to_integer(System.get_env("OBAN_POOL_SIZE") || "12"),
timeout: 15000,
socket_options: maybe_ipv6,
stacktrace: true,
prepare: :unnamed
ECTO_IPV6 is properly set to true.
Any advice on how to properly configure Phoenix/Oban/Ecto with Fly’s managed Postgres/PgBouncer would be super helpful!
Thanks ![]()
