postgresql/src/include
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
..
access Restore pg_pread and friends. 2022-09-29 13:12:11 +13:00
backup Move basebackup code to new directory src/backend/backup 2022-08-10 14:03:23 -04:00
bootstrap Harmonize more lexer function parameter names. 2022-09-22 13:27:16 -07:00
catalog Introduce SYSTEM_USER 2022-09-29 15:05:40 +09:00
commands Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
common Mark sigint_interrupt_enabled as sig_atomic_t 2022-09-29 14:28:13 +09:00
datatype Fix overflow hazards in interval input and output conversions. 2022-04-02 16:12:29 -04:00
executor Harmonize parameter names in storage and AM code. 2022-09-19 19:18:36 -07:00
fe_utils Revert 56-bit relfilenode change and follow-up commits. 2022-09-28 09:55:28 -04:00
foreign Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
jit Add central declarations for dlsym()ed symbols 2022-07-17 17:23:42 -07:00
lib Rename shadowed local variables 2022-10-05 21:01:41 +13:00
libpq Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
mb Harmonize parameter names in storage and AM code. 2022-09-19 19:18:36 -07:00
nodes Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
optimizer Revert "Optimize order of GROUP BY keys". 2022-10-03 10:56:16 -04:00
parser Introduce SYSTEM_USER 2022-09-29 15:05:40 +09:00
partitioning Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
pch meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
port mingw: Define PGDLLEXPORT as __declspec (dllexport) as done for msvc 2022-09-30 10:50:05 -07:00
portability Fix obsolete comments in instr_time.h. 2022-08-09 11:50:03 +12:00
postmaster Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
regex Consistently use named parameters in regex code. 2022-09-19 15:10:24 -07:00
replication pgstat: Prevent stats reset from corrupting slotname by removing slotname 2022-10-08 09:43:29 -07:00
rewrite Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
snowball Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
statistics Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
storage Revert 56-bit relfilenode change and follow-up commits. 2022-09-28 09:55:28 -04:00
tcop Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
tsearch Introduce t_isalnum() to replace t_isalpha() || t_isdigit() tests. 2022-10-06 11:08:56 -04:00
utils pgstat: Prevent stats reset from corrupting slotname by removing slotname 2022-10-08 09:43:29 -07:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Add definition pg_attribute_aligned() for MSVC 2022-09-21 10:11:23 +09:00
fmgr.h Mark all symbols exported from extension libraries PGDLLEXPORT. 2022-07-17 18:50:14 -07:00
funcapi.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
getopt_long.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
Makefile Move gramparse.h to src/backend/parser 2022-09-14 10:57:13 +07:00
meson.build meson: Add support for building with precompiled headers 2022-10-06 17:19:30 -07:00
miscadmin.h Introduce SYSTEM_USER 2022-09-29 15:05:40 +09:00
pg_config.h.in Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Remove our artificial PG_SOMAXCONN limit on listen queue length. 2022-08-23 10:15:06 -04:00
pg_getopt.h Apply PGDLLIMPORT markings broadly. 2022-04-08 08:16:38 -04:00
pg_trace.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgstat.h pgstat: Prevent stats reset from corrupting slotname by removing slotname 2022-10-08 09:43:29 -07:00
pgtar.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
pgtime.h Harmonize more parameter names in bulk. 2022-09-20 13:09:30 -07:00
port.h Restore pg_pread and friends. 2022-09-29 13:12:11 +13:00
postgres.h Convert *GetDatum() and DatumGet*() macros to inline functions 2022-09-27 20:50:21 +02:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2022 2022-01-07 19:04:57 -05:00
windowapi.h Update copyright for 2022 2022-01-07 19:04:57 -05:00