mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-31 17:07:20 +02:00
Don't run RelationInitTableAccessMethod in a long-lived context.
Some code paths in this function perform syscache lookups, which can lead to table accesses and possibly leakage of cruft into the caller's context. If said context is CacheMemoryContext, we eventually will have visible bloat. But fixing this is no harder than moving one memory context switch step. (The other callers don't have a problem.) Andres Freund and I independently found this via valgrind testing. Back-patch to v12 where this code was added. Discussion: https://postgr.es/m/20210317023101.anvejcfotwka6gaa@alap3.anarazel.de Discussion: https://postgr.es/m/3816764.1616104288@sss.pgh.pa.us
This commit is contained in:
parent
5368369701
commit
ea3989f349
12
src/backend/utils/cache/relcache.c
vendored
12
src/backend/utils/cache/relcache.c
vendored
@ -3529,6 +3529,13 @@ RelationBuildLocalRelation(const char *relname,
|
|||||||
|
|
||||||
rel->rd_rel->relam = accessmtd;
|
rel->rd_rel->relam = accessmtd;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RelationInitTableAccessMethod will do syscache lookups, so we mustn't
|
||||||
|
* run it in CacheMemoryContext. Fortunately, the remaining steps don't
|
||||||
|
* require a long-lived current context.
|
||||||
|
*/
|
||||||
|
MemoryContextSwitchTo(oldcxt);
|
||||||
|
|
||||||
if (relkind == RELKIND_RELATION ||
|
if (relkind == RELKIND_RELATION ||
|
||||||
relkind == RELKIND_SEQUENCE ||
|
relkind == RELKIND_SEQUENCE ||
|
||||||
relkind == RELKIND_TOASTVALUE ||
|
relkind == RELKIND_TOASTVALUE ||
|
||||||
@ -3552,11 +3559,6 @@ RelationBuildLocalRelation(const char *relname,
|
|||||||
*/
|
*/
|
||||||
EOXactListAdd(rel);
|
EOXactListAdd(rel);
|
||||||
|
|
||||||
/*
|
|
||||||
* done building relcache entry.
|
|
||||||
*/
|
|
||||||
MemoryContextSwitchTo(oldcxt);
|
|
||||||
|
|
||||||
/* It's fully valid */
|
/* It's fully valid */
|
||||||
rel->rd_isvalid = true;
|
rel->rd_isvalid = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user