sigu

sigu

Postgres connection count always increasing, never drops

We have an application running on EC2 which connects to a database on RDS.

Over the past couple of weeks, we noticed the connections to the database were always filling up after which
we were not able to make new requests to the database with the following error

%Postgrex.Error{connection_id: nil, message: nil, postgres: %{code: :too_many_connections, file: "postinit.c", line: "803", message: "remaining connection slots are reserved for non-replication superuser connections", pg_code: "53300", routine: "InitPostgres", severity: "FATAL", unknown: "FATAL"}, query: nil}

The connections always go up in count and rarely drops down to a lower number. On rebooting the server the connection count is reset then it starts to increment again never dropping.

More information

The pool size is set to 10 on the prod.secret.exs.
We can reproduce this by uploading and processing a CSV file on the application.

Questions

  • Why are the connections always increasing?
  • Is there a way of closing the unused connections or restricting it to a maximum?

Most Liked

outlog

outlog

great!

what is the current postgrex code? sounds like you are opening up a db listener per client connection - think you are better off with one long-lived listener that then emits pubsub events…

I’ve used Boltun in the past which gives a nice API - https://github.com/bitgamma/boltun - but better/more recent solutions might be around…

kip

kip

ex_cldr Core Team

I’m sure more knowledgeable souls will leap in. But what your graph is showing that your RDS instance has run out of connections. If your Ecto Repo pool is 10 connections and you are running out of connections on the DB side at 80 then that suggests:

  1. Some other app(s) is/are connecting to your DB and using connections
  2. Your pool isn’t really 10 connections (but its unlikely to be 80!
  3. Something is causing the Repo to crash and restart but the old connections are still being held open on the DB side (this seems unlikely since you would see log messages). And it would have to crash and restart 8 times!

Maybe that at least gives you some angles to consider …

outlog

outlog

is ecto and especially postgrex latest versions?

do you have ec2 auto-scaling enabled? (this would fit the issue/symptoms exactly)…

mcrumm

mcrumm

Phoenix Core Team

You can use the terminate/2 callback in your LiveView to unsubscribe from notifications when the user navigates away from the page.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement