postgresql/src/include/utils
Andres Freund 06dbd619bf pgstat: Prevent stats reset from corrupting slotname by removing slotname
Previously PgStat_StatReplSlotEntry contained the slotname, which was mainly
used when writing out the stats during shutdown, to identify the slot in the
serialized data (at runtime the index in ReplicationSlotCtl->replication_slots
is used, but that can change during a restart). Unfortunately the slotname was
overwritten when the slot's stats were reset.

That turned out to only cause "real" problems if the slot was active during
the reset, triggering an assertion failure at the next
pgstat_report_replslot(). In other paths the stats were re-initialized during
pgstat_acquire_replslot().

Fix this by removing slotname from PgStat_StatReplSlotEntry. Instead we can
get the slot's name from the slot itself. Besides fixing a bug, this also is
architecturally cleaner (a name is not really statistics). This is safe
because stats, for a slot removed while shut down, will not be restored at
startup.

In 15 the slotname is not removed, but renamed, to avoid changing the stats
format. In master, bump PGSTAT_FILE_FORMAT_ID.

This commit does not contain a test for the fix. I think this can only be
tested by a tap test starting pg_recvlogical in the background and checking
pg_recvlogical's output. That type of test is notoriously hard to be reliable,
so committing it shortly before the release is wrapped seems like a bad idea.

Reported-by: Jaime Casanova <jcasanov@systemguards.com.ec>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/YxfagaTXUNa9ggLb@ahch-to
Backpatch: 15-, where the bug was introduced in 5891c7a8ed
2022-10-08 09:43:29 -07:00
..
.gitignore Revert "Add gitignore entries for jsonpath_gram.h" 2019-03-23 00:19:34 +01:00
acl.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
aclchk_internal.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
array.h Add construct_array_builtin, deconstruct_array_builtin 2022-07-01 11:23:15 +02:00
arrayaccess.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
ascii.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
attoptcache.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
backend_progress.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
backend_status.h Use actual backend IDs in pg_stat_get_backend_idset() and friends. 2022-09-29 12:14:39 -04:00
builtins.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
bytea.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
cash.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
catcache.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
combocid.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
date.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
datetime.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
datum.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
dsa.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
dynahash.h Fix various typos, grammar and code style in comments and docs 2022-01-25 09:40:04 +09:00
elog.h Add optional parameter to PG_TRY() macros 2022-10-06 10:08:31 +13:00
evtcache.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
expandeddatum.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
expandedrecord.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
float.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
fmgrtab.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
formatting.h Revert SQL/JSON features 2022-09-01 17:07:14 -04:00
freepage.h Fix relptr's encoding of the base address. 2022-06-27 11:34:26 +12:00
geo_decls.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
guc.h Renumber GUC flags for a bit more sanity. 2022-09-27 11:51:06 -04:00
guc_hooks.h Split up guc.c for better build speed and ease of maintenance. 2022-09-13 11:11:45 -04:00
guc_tables.h Split up guc.c for better build speed and ease of maintenance. 2022-09-13 11:11:45 -04:00
help_config.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
hsearch.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
index_selfuncs.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
inet.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
inval.h Change internal RelFileNode references to RelFileNumber or RelFileLocator. 2022-07-06 11:39:09 -04:00
json.h Revert SQL/JSON features 2022-09-01 17:07:14 -04:00
jsonb.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
jsonfuncs.h Revert SQL/JSON features 2022-09-01 17:07:14 -04:00
jsonpath.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
logtape.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
lsyscache.h Move common catalog cache access routines to lsyscache.c 2022-08-02 10:47:22 +05:30
memdebug.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
memutils.h Remove MemoryContextContains(). 2022-10-06 13:35:31 -04:00
memutils_internal.h Improve our ability to detect bogus pointers passed to pfree et al. 2022-10-06 21:24:00 -04:00
memutils_memorychunk.h Various cleanups of the new memory context header code 2022-08-31 07:33:54 +12:00
meson.build meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
multirangetypes.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
numeric.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
old_snapshot.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
palloc.h Expand palloc/pg_malloc API for more type safety 2022-09-12 08:45:03 +02:00
partcache.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_crc.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pg_locale.h Split up guc.c for better build speed and ease of maintenance. 2022-09-13 11:11:45 -04:00
pg_lsn.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
pg_rusage.h Remove configure probe for sys/resource.h and refactor. 2022-08-14 00:09:47 +12:00
pgstat_internal.h pgstat: Prevent stats reset from corrupting slotname by removing slotname 2022-10-08 09:43:29 -07:00
pidfile.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
plancache.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
portal.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
ps_status.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
queryenvironment.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
queryjumble.h Remove definition of JUMBLE_SIZE from queryjumble.h 2022-10-05 14:27:50 +09:00
rangetypes.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
regproc.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
rel.h Convert macros to static inline functions (rel.h) 2022-10-07 16:16:50 +02:00
relcache.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
relfilenumbermap.h Include common/relpath.h in utils/relfilenumbermap.h 2022-09-27 13:35:20 -04:00
relmapper.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
relptr.h Fix relptr's encoding of the base address. 2022-06-27 11:34:26 +12:00
reltrigger.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
resowner.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
resowner_private.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
rls.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
ruleutils.h Add public ruleutils.c entry point to deparse a Query. 2022-03-28 11:19:37 -04:00
sampling.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
selfuncs.h Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
sharedtuplestore.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
snapmgr.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
snapshot.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
sortsupport.h Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
spccache.h Add missing 'extern' to function prototypes. 2022-05-12 12:39:33 -07:00
syscache.h Allow granting SET and ALTER SYSTEM privileges on GUC parameters. 2022-04-06 13:24:33 -04:00
timeout.h pgstat: store statistics in shared memory. 2022-04-06 21:29:46 -07:00
timestamp.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
tuplesort.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
tuplestore.h Remove all traces of tuplestore_donestoring() in the C code 2022-02-17 09:52:02 +09:00
typcache.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
tzparser.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
uuid.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
varbit.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
varlena.h Adjust assorted hint messages that list all valid options. 2022-09-16 14:53:12 +02:00
wait_event.h Remove the restriction that the relmap must be 512 bytes. 2022-07-26 14:56:25 -04:00
xid8.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
xml.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00