Improve pgstat_get_entry_ref_cached() behavior on out-of-memory errors A failure in allocating a new cache entry in the backend-level hash table holding references to shared stats entries would leave the table in an inconsistent state, crash or FATAL at session exit, depending on if there are pending stats.
Rather than leaving things in an inconsistent state on OOM, the code is switched to use MemoryContextAllocExtended(MCXT_ALLOC_NO_OOM), so as an allocation failure leads to a cleanup of the hash table before issuing the allocation error. The problem is unlikely going to show up in practice, so no backpatch is done. Note that shared memory is not impacted, only a backend-level hash table. Reported-by: Alex Masterov <[email protected]> Discussion: https://postgr.es/m/CA+8z=zumV9sscgK=j1Es+-564maVoO9CMDdB9CsW9=fczic...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/16ebc196d8926823bc8d64931557b679cecd67aa Modified Files -------------- src/backend/utils/activity/pgstat_shmem.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
