vitorquintanilha

vitorquintanilha

Reconnect on connection failure for Ecto and Postgres

Hello there.

I’m using ecto 3.10.3, ecto_sql 3.10.1 and postgrex0.17.2 on a rather simple service. For reason beyond my control my Postgres DB faces some small downtimes every now and then. This trigger alerts that are annoying for my team.

I wanted to make my service more resilient to those downtimes. Specifically, I wanted to have my service trying to reconnect to the DB for a couple of minutes before crashing/logging errors.

I’ve found that postgresx has some configuration options like backoff_type and max_restarts, which I think could help me. However, I see that on ecto_sql those seem to be forced to be backoff_type: :stop and max_restarts: 0.

Is there any other way I can make my system more resilient to small DB downtimes?

Thanks

Most Liked

cevado

cevado

Can you provide the error message? And the scenario of that messages? Given what you said I’m assuming it is actually breaking your app and on app restart it doesn’t apply the backoff strategy.

afaik backoff_type uses the default of db_connection that is :rand_exp. but anyway, you can override that configuration on your config
https://hexdocs.pm/db_connection/2.4.1/DBConnection.html#start_link/2

you could do:

config :your_app, YourApp.Repo,
  backoff_type: :rand_exp,
  backoff_max: ...,
  backoff_min: ...,
  max_restarts: ...

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

We're in Beta

About us Mission Statement