From: | Jeff Janes <jeff(dot)janes(at)gmail(dot)com> |
---|---|
To: | Hubert Lubaczewski <depesz(at)depesz(dot)com> |
Cc: | Pg Bugs <pgsql-bugs(at)postgresql(dot)org> |
Subject: | Re: PostgreSQL (9.3 and 9.6) eats all memory when using many tables |
Date: | 2016-06-12 20:50:48 |
Message-ID: | CAMkU=1xOLwvzXDgw8=QAa-oEONmCtjoP7O-=CVqN3Cv2o41kyw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Thu, Jun 9, 2016 at 8:46 AM, hubert depesz lubaczewski
<depesz(at)depesz(dot)com> wrote:
> Hi,
> so, we are running 9.3.10 in production, but I tested it in 9.6, and the
> problem seems to be there too in 9.6, though to much lesser extent.
>
> In our database we have ~ 70000 tables (~ 180 tables in ~ 400 schemas).
>
> So far we used application in such a way that each connection could use
> only tables from single schema.
>
> But then, we switched situation to where single connection (very long,
> as it's reused thanks to pgbouncer) can effectively query tables from
> all schemas.
>
> And this caused memory usage to explode, to the point that our server
> wasn't able to handle it (64gb of mem gone).
You should probably use pgbouncer's server_lifetime to force
connections to be discarded and recreated every now and then. That
parameter seems to exist specifically for dealing with this kind of
problem.
....
> This effectively does:
> select 1, 1, * from <table> limit <1..3>
> for each table.
Is all of that necessary? Can't you reproduce the problem just as
well with just "select count(*) from <table>;" ?
> on 9.3 after ~ 35000 tables, pg process grew by 1GB, and it wasn't shared
> buffers, as smaps showed that the memory was anonymous.
>
> In 9.6, after 35000 tables it grew by ~ 71MB. Which is much better, but still not really optimal.
>
> The same situation happens when I was *not* using prepared statements on server side.
>
> Basically it looks that postgresql "caches" query plans? parsed elements?
It is caching metadata for every table and index touched by the backend.
Cheers,
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | hubert depesz lubaczewski | 2016-06-13 09:39:07 | Re: PostgreSQL (9.3 and 9.6) eats all memory when using many tables |
Previous Message | Julien Rouhaud | 2016-06-12 17:58:10 | Re: BUG #14183: pgAdminIII doesn't display NEGATOR entries |