fedme

fedme

How to investigate DB errors like "client timed out because it queued and checked out the connection for longer than..."

Hi,

We’re starting to collect many of these errors in our logs and I am trying to understand how we can investigate them further:

Postgrex.Protocol (#PID<0.1264.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.1555.0> timed out because it queued and checked out the connection for longer than 15000ms

I have read this topic and I understand these are caused by slow queries.
Now I am wondering, can Postgrex/Ecto be configured to log the slow query together with the above error?

I know I can find slow queries in a different way (e.g. with Postgres’pg_stat_statements extension), but it would be extremely useful if I could get some indication of what DB operation caused the timeout detailed in the error log.

Is that error log about a DB connection pool process crashing due to a timeout? Will it cause the caller process to crash as well? Maybe there’s a way to trap the timeout and log it somehow?

Thanks for your help!

Marked As Solved

LostKobrakai

LostKobrakai

Not sure you understood my comments correctly. You can get results by looking for slow queries, but a pool timeout is not guaranteed to come from a slow query. It could just as much be from a lot of fast queries accumulating their time needed to complete – or to an extreme by not running any query at all, but just leaving the connection checked out for longer than the timeout.

The better way to diagnose this is to see if the stacktrace printed can be extended to get out of general code paths and into ones which are useful for debugging.

Also Liked

pdgonzalez872

pdgonzalez872

Moving away from Elixir here, you could also enable logs on Postgres and monitor them as you play around with the suggestions above. I have some notes about this here. Please post your findings!

LostKobrakai

LostKobrakai

Yes and yes. But given this is a timeout for the pooled connection this means it’s not bound to a particular query. You can e.g. do Repo.checkout(fn -> Process.sleep(:infinity) end) and you’d get that error without any query involved.

c4710n

c4710n

IMO, you have to diagnose this problem from the slow query.

Edit: checkout the below explaination of @LostKobrakai.


If you guess that the root cause is slow queries. You can find the slow queries by using the tools provided by PostgreSQL (which you said above). Or, you can use Ecto directly. Here’s how:

Ecto supports metrics which are reported by :telemetry.
You can log slow queries like this - Output slow Ecto queries to logs · GitHub.

(The gist is picked randomly from the Internet…

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

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 Postgres...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
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

Latest on Elixir Forum

We're in Beta

About us Mission Statement