-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres memory leak/high usage triggered by Ecto connection pool #3284
Comments
This is caused by our query cache which is... surprise, surprise, per table! Given you have so many tables, you may want to disable it. I will work on something. |
Set |
Hey Jose, I just saw that in commit 377fdbacbe3170039bfc1806881f9650c16251b6 the changes of Why was that? Without being able to set |
Hi @sezaru! That's because |
Oh, indeed! You are absolutely right. Sorry, I didn't realise that.. |
Hello,
I'm having an issue where I get a very high memory usage until I get OOM regardless of how much memory I have (I have 64GB btw).
I first thought it was a Postgres issue, but I can trigger it with MySQL and at the same time I cannot trigger it if using identical queries with a python implementation or an Elixir implementation using Postgrex directly.
It only happens when using Ecto connection pool, even if I limit the pool to 1 connection only.
Environment
Current behavior
So, the issue happens when I insert data in different tables, in my case, I have more than 12k tables. Each time I do a new insert query to a new table (new in the sense that I didn't touch it yet with the current connection) it will increase the memory usage and never release it (only when I close the connection).
To help diagnose it, I created some self-contained Elixir scripts that reproduce the issue, you only need to run it with Postgres installed and with the Ecto and Postgrex dependency too obviously. Also, you need to create the database with
create database test_dev;
viapsql
or other Postgres client.The first script creates the tables:
The second script triggers the issue:
The third script runs an equivalent code as the second one but using Postgrex directly, it doesn't trigger the issue:
As you can see from the code, basically what it does is create a lot of rows to be inserted into one of the 800 tables created, then it selects one of these tables at random and does the query. The scripts will run infinitely until the user stops it or it runs out of memory (in the case of the second script).
To see the memory usage, you can simply use
htop
and filter to only show postgres processes, that way you can see the connection elixir will do with the postgres server and how the memory increases.Also, for completeness, I ran a little python script called psrecord that logs the memory usage of a process, these are the results I got (note that I stopped it when it reached 2 GB usage).
Running the second script:
Running the third script:
Thanks for the help!
The text was updated successfully, but these errors were encountered: