pgsql: Improve pgstat_get_entry_ref_cached() behavior on out-of-memory - Mailing list pgsql-committers

From Michael Paquier
Subject pgsql: Improve pgstat_get_entry_ref_cached() behavior on out-of-memory
Date
Msg-id E1wlhrd-000EOz-0T@gemulon.postgresql.org
Whole thread
List pgsql-committers
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 <amasterov@gmail.com>
Discussion: https://postgr.es/m/CA+8z=zumV9sscgK=j1Es+-564maVoO9CMDdB9CsW9=FCziCj3w@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(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Fix RLS checks for FOR PORTION OF leftover rows
Next
From: Álvaro Herrera
Date:
Subject: pgsql: Move code to get_tables_to_repack_partitioned