pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Prevent memory leaks associated with relcache rd_partcheck struc 3+ messages / 1 participants [nested] [flat]
* pgsql: Prevent memory leaks associated with relcache rd_partcheck struc @ 2019-04-13 17:22 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2019-04-13 17:22 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Prevent memory leaks associated with relcache rd_partcheck structures. The original coding of generate_partition_qual() just copied the list of predicate expressions into the global CacheMemoryContext, making it effectively impossible to clean up when the owning relcache entry is destroyed --- the relevant code in RelationDestroyRelation() only managed to free the topmost List header :-(. This resulted in a session-lifespan memory leak whenever a table partition's relcache entry is rebuilt. Fortunately, that's not normally a large data structure, and rebuilds shouldn't occur all that often in production situations; but this is still a bug worth fixing back to v10 where the code was introduced. To fix, put the cached expression tree into its own small memory context, as we do with other complicated substructures of relcache entries. Also, deal more honestly with the case that a partition has an empty partcheck list; while that probably isn't a case that's very interesting for production use, it's legal. In passing, clarify comments about how partitioning-related relcache data structures are managed, and add some Asserts that we're not leaking old copies when we overwrite these data fields. Amit Langote and Tom Lane Discussion: https://postgr.es/m/7961.1552498252@sss.pgh.pa.us Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/5f1433ac5e7f943b29ef01266b6b8fc915e6b917 Modified Files -------------- src/backend/partitioning/partdesc.c | 23 +++++++++++++--- src/backend/utils/cache/partcache.c | 54 ++++++++++++++++++++++++++----------- src/backend/utils/cache/relcache.c | 20 +++++++++----- src/include/utils/rel.h | 6 +++-- 4 files changed, 75 insertions(+), 28 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Prevent memory leaks associated with relcache rd_partcheck struc @ 2019-04-13 17:22 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2019-04-13 17:22 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Prevent memory leaks associated with relcache rd_partcheck structures. The original coding of generate_partition_qual() just copied the list of predicate expressions into the global CacheMemoryContext, making it effectively impossible to clean up when the owning relcache entry is destroyed --- the relevant code in RelationDestroyRelation() only managed to free the topmost List header :-(. This resulted in a session-lifespan memory leak whenever a table partition's relcache entry is rebuilt. Fortunately, that's not normally a large data structure, and rebuilds shouldn't occur all that often in production situations; but this is still a bug worth fixing back to v10 where the code was introduced. To fix, put the cached expression tree into its own small memory context, as we do with other complicated substructures of relcache entries. Also, deal more honestly with the case that a partition has an empty partcheck list; while that probably isn't a case that's very interesting for production use, it's legal. In passing, clarify comments about how partitioning-related relcache data structures are managed, and add some Asserts that we're not leaking old copies when we overwrite these data fields. Amit Langote and Tom Lane Discussion: https://postgr.es/m/7961.1552498252@sss.pgh.pa.us Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/089e4d405d0f3b94c74a2c6a54357a84a681754b Modified Files -------------- src/backend/utils/cache/partcache.c | 82 +++++++++++++++++++++++++++---------- src/backend/utils/cache/relcache.c | 20 +++++---- src/include/utils/rel.h | 8 +++- 3 files changed, 80 insertions(+), 30 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Prevent memory leaks associated with relcache rd_partcheck struc @ 2019-04-13 17:22 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 3+ messages in thread From: Tom Lane @ 2019-04-13 17:22 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Prevent memory leaks associated with relcache rd_partcheck structures. The original coding of generate_partition_qual() just copied the list of predicate expressions into the global CacheMemoryContext, making it effectively impossible to clean up when the owning relcache entry is destroyed --- the relevant code in RelationDestroyRelation() only managed to free the topmost List header :-(. This resulted in a session-lifespan memory leak whenever a table partition's relcache entry is rebuilt. Fortunately, that's not normally a large data structure, and rebuilds shouldn't occur all that often in production situations; but this is still a bug worth fixing back to v10 where the code was introduced. To fix, put the cached expression tree into its own small memory context, as we do with other complicated substructures of relcache entries. Also, deal more honestly with the case that a partition has an empty partcheck list; while that probably isn't a case that's very interesting for production use, it's legal. In passing, clarify comments about how partitioning-related relcache data structures are managed, and add some Asserts that we're not leaking old copies when we overwrite these data fields. Amit Langote and Tom Lane Discussion: https://postgr.es/m/7961.1552498252@sss.pgh.pa.us Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/d4c50b4b1f86f639992b23eb183575ad6f0653ca Modified Files -------------- src/backend/catalog/partition.c | 66 +++++++++++++++++++++++++++++--------- src/backend/utils/cache/relcache.c | 31 +++++++++++------- src/include/utils/rel.h | 8 +++-- 3 files changed, 76 insertions(+), 29 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2019-04-13 17:22 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-04-13 17:22 pgsql: Prevent memory leaks associated with relcache rd_partcheck struc Tom Lane <tgl@sss.pgh.pa.us> 2019-04-13 17:22 pgsql: Prevent memory leaks associated with relcache rd_partcheck struc Tom Lane <tgl@sss.pgh.pa.us> 2019-04-13 17:22 pgsql: Prevent memory leaks associated with relcache rd_partcheck struc Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox