From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Justin Pryzby <pryzby(at)telsasoft(dot)com> |
Cc: | Guillaume Lelarge <guillaume(at)lelarge(dot)info>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Lots of memory allocated when reassigning Large Objects |
Date: | 2021-11-29 18:40:31 |
Message-ID: | 1280909.1638211231@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Justin Pryzby <pryzby(at)telsasoft(dot)com> writes:
> I reproduced the issue like this.
> psql postgres -c 'CREATE ROLE two WITH login superuser'
> psql postgres two -c "SELECT lo_import('/dev/null') FROM generate_series(1,22111)" >/dev/null
> psql postgres -c 'SET client_min_messages=debug; SET log_statement_stats=on;' -c 'begin; REASSIGN OWNED BY two TO pryzbyj; rollback;'
Confirmed here, although I needed to use a lot more than 22K large objects
to see a big leak.
> I didn't find the root problem, but was able to avoid the issue by creating a
> new mem context. I wonder if there are a bunch more issues like this.
I poked into it with valgrind, and identified the major leak as being
stuff that is allocated by ExecOpenIndices and not freed by
ExecCloseIndices. The latter knows it's leaking:
/*
* XXX should free indexInfo array here too? Currently we assume that
* such stuff will be cleaned up automatically in FreeExecutorState.
*/
On the whole, I'd characterize this as DDL code using pieces of the
executor without satisfying the executor's expectations as to environment
--- specifically, that it'll be run in a memory context that doesn't
outlive executor shutdown. Normally, any one DDL operation does a limited
number of catalog updates so that small per-update leaks don't cost that
much ... but REASSIGN OWNED creates a loop that can invoke ALTER OWNER
many times.
I think your idea of creating a short-lived context is about right.
Another idea we could consider is to do that within CatalogTupleUpdate;
but I'm not sure that the cost/benefit ratio would be good for most
operations. Anyway I think ALTER OWNER has other leaks outside the
index-update operations, so we'd still need to do this within
REASSIGN OWNED's loop.
DROP OWNED BY likely has similar issues.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Guillaume Lelarge | 2021-11-29 19:04:06 | Re: Lots of memory allocated when reassigning Large Objects |
Previous Message | Bossart, Nathan | 2021-11-29 18:25:24 | Re: Postgres restart in the middle of exclusive backup and the presence of backup_label file |