ajur58

ajur58

Fly.io + Supabase DB: Too many connections after releases

Hi everyone,

I’m posting because I assume this must be a common issue, but I’ve been going in circles and haven’t
found a clean, reliable pattern yet.

I run a fairly simple Phoenix app on Fly.io with a rolling deploy setup for two machines: one web, one worker for Oban/cron-heavy background work.

The database is Supabase Pro Postgres.

Each app machine has a fixed DB pool (web=10, worker=15), and the app works fine during normal operation.

The problem appears on deploys, especially consecutive deploys:

  • new machines start
  • old machines are still around briefly
  • old idle DB connections from the previous release do not get cleaned up for a considerable time
  • connection count spikes and can stay high enough that Postgres starts rejecting new connections

On Supabase I then see errors like:

  • remaining connection slots are reserved for roles with the SUPERUSER attribute
  • sorry, too many clients already

My current solution is:

  • run a delayed post-deploy DB hygiene task from the worker node only
  • wait about 3 minutes after startup
  • then terminate stale DB sessions that are idle / idle in transaction and older than 2
    minutes

That is working better than trying to do cleanup in Fly’s release_command, because
release_command runs too early, before old Machines have fully exited and before their sessions are
actually stale.

But I can’t help to think that I must be doing something wrong? Is this a common issue?

Thanks for your help!

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement