postgresql/src/include/utils
Michael Paquier 850b9218c8 Fix PANIC with track_functions due to concurrent drop of pgstats entries
pgstat_drop_entry_internal() generates an ERROR if facing a pgstats
entry already marked as dropped.  With a workload doing a lot of
concurrent CALL and DROP/CREATE PROCEDURE, it could be possible for
AtEOXact_PgStat_DroppedStats(), that wants to do transactional drops, to
find entries that are already dropped, after a commit record has been
written.  In this case, ERRORs are upgraded to PANIC, taking down the
server.

This issue is fixed by making pgstat_drop_entry() optionally more
tolerant to concurrent drops, adding to the routine a missing_ok option
to make some of its callers more tolerant (spoiler: some of the callers
want a strict behavior, like replication slots and backend stats).
pgstat_drop_entry_internal() cannot be called anymore for an entry
marked as dropped, hence its error is replaced by an assertion.
Functions are handled as a special case in core; this problem could also
apply to custom stats kinds depending on what an extension does.
track_functions is costly when enabled (disabled by default), which is
perhaps the main reason why this has not be found yet.

A similar version of this patch has been proposed by Sami Imseih on a
different thread for a feature in development.  This version has tweaked
here by me for the sake of fixing this issue.

Reported-by: zhanglihui <zlh21343@163.com>
Author: Sami Imseih <samimseih@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/19520-73873648d44793cf@postgresql.org
Backpatch-through: 15
2026-06-18 11:49:30 +09:00
..
.gitignore Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
acl.h Allow choosing specific grantors via GRANT/REVOKE ... GRANTED BY. 2026-03-19 11:41:39 -05:00
aclchk_internal.h Allow choosing specific grantors via GRANT/REVOKE ... GRANTED BY. 2026-03-19 11:41:39 -05:00
array.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
arrayaccess.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
ascii.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
attoptcache.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
backend_progress.h Online enabling and disabling of data checksums 2026-04-03 22:58:51 +02:00
backend_status.h Convert all remaining subsystems to use the new shmem allocation API 2026-04-06 02:13:10 +03:00
builtins.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
bytea.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
cash.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
catcache.h Clarify where various catcache.h dlist_nodes are used 2026-01-06 14:39:36 +13:00
combocid.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
conffiles.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
date.h Remove #include <math.h> where not needed 2026-01-15 19:09:47 +01:00
datetime.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
datum.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
dsa.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
elog.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
evtcache.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
expandeddatum.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
expandedrecord.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
float.h Make geometry cast functions error safe 2026-03-29 20:40:50 +02:00
fmgrtab.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
formatting.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
freepage.h Rename AssertVariableIsOfType to StaticAssertVariableIsOfType 2026-02-03 08:45:24 +01:00
funccache.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
geo_decls.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
guc.h ssl: Serverside SNI support for libpq 2026-03-18 12:37:11 +01:00
guc_hooks.h instrumentation: Use Time-Stamp Counter on x86-64 to lower overhead 2026-04-07 13:00:24 -04:00
guc_tables.h instrumentation: Use Time-Stamp Counter on x86-64 to lower overhead 2026-04-07 13:00:24 -04:00
help_config.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
hsearch.h Remove HASH_DIRSIZE, always use the default algorithm to select it 2026-04-04 02:40:28 +03:00
index_selfuncs.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
inet.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
injection_point.h Convert all remaining subsystems to use the new shmem allocation API 2026-04-06 02:13:10 +03:00
inval.h Reduce presence of syscache.h in src/include/ 2026-04-09 08:49:36 +09:00
json.h json format for COPY TO 2026-03-20 08:40:04 -04:00
jsonb.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
jsonfuncs.h make immutability tests in to_json and to_jsonb complete 2026-03-17 11:28:33 -04:00
jsonpath.h Add additional jsonpath string methods 2026-04-02 15:19:49 -04:00
logtape.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
lsyscache.h Fix missed checks for hashability of container-type equality. 2026-06-08 11:48:16 -04:00
memdebug.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
memutils.h Make palloc_array() and friends safe against integer overflow. 2026-05-11 05:13:46 -07:00
memutils_internal.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
memutils_memorychunk.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
meson.build Fix build inconsistency due to the generation of wait-event code 2026-02-02 08:02:39 +09:00
multirangetypes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
numeric.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
palloc.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
partcache.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_crc.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_locale.h Don't accept length of -1 in pg_locale.h APIs. 2026-05-15 11:09:15 -07:00
pg_locale_c.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_lsn.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pg_rusage.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
pgstat_internal.h Fix PANIC with track_functions due to concurrent drop of pgstats entries 2026-06-18 11:49:30 +09:00
pgstat_kind.h Add support for lock statistics in pgstats 2026-03-24 15:32:09 +09:00
pidfile.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
plancache.h Add some const qualifiers enabled by typeof_unqual change on copyObject 2026-03-19 06:35:54 +01:00
portal.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
ps_status.h Speedup and increase usability of set proc title functions 2023-02-20 16:18:27 +13:00
queryenvironment.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
rangetypes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
regproc.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
rel.h Prevent access to other sessions' temp tables 2026-05-14 15:01:17 +03:00
relcache.h Use schema-qualified names in EXCEPT clause error messages. 2026-05-08 10:00:26 +05:30
relfilenumbermap.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
relmapper.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
relptr.h Rename AssertVariableIsOfType to StaticAssertVariableIsOfType 2026-02-03 08:45:24 +01:00
reltrigger.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
resowner.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
rls.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
ruleutils.h Add pg_get_tablespace_ddl() function 2026-04-05 10:54:54 -04:00
sampling.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
selfuncs.h Discount the metapage when estimating number of index pages visited. 2026-03-20 14:50:53 -04:00
sharedtuplestore.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
skipsupport.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
snapmgr.h Use GlobalVisState in vacuum to determine page level visibility 2026-03-24 14:50:59 -04:00
snapshot.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
sortsupport.h Perform radix sort on SortTuples with pass-by-value Datums 2026-02-14 13:50:06 +07:00
spccache.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
syscache.h Switch SysCacheIdentifier to a typedef enum 2026-02-18 09:58:38 +09:00
timeout.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
timestamp.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
tuplesort.h Perform radix sort on SortTuples with pass-by-value Datums 2026-02-14 13:50:06 +07:00
tuplestore.h Pre-beta mechanical code beautification, step 1: run pgindent. 2026-05-13 10:34:17 -04:00
typcache.h Extend DomainHasConstraints() to optionally check constraint volatility 2026-03-12 18:04:16 -04:00
tzparser.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
usercontext.h Perform logical replication actions as the table owner. 2023-04-04 11:25:23 -04:00
uuid.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
varbit.h Remove bits* typedefs. 2026-03-30 16:12:08 -05:00
varlena.h Expose helper functions scan_quoted_identifier and scan_identifier. 2026-04-06 11:13:25 -04:00
wait_classes.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
wait_event.h Convert all remaining subsystems to use the new shmem allocation API 2026-04-06 02:13:10 +03:00
xid8.h Update copyright for 2026 2026-01-01 13:24:10 -05:00
xml.h Make many cast functions error safe 2026-03-24 12:08:22 +01:00