postgresql/src/backend
Fujii Masao 614b7f18b3 Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.
Commit 2c8dd05d6c added the atomic variable writtenUpto into
walreceiver's shared memory information. It's initialized only
when walreceiver started up but could be read via pg_stat_wal_receiver
view anytime, i.e., even before it's initialized. In the server built
with --disable-atomics and --disable-spinlocks, this uninitialized
atomic variable read could cause "invalid spinlock number: 0" error.

This commit changed writtenUpto so that it's initialized at
the postmaster startup, to avoid the uninitialized variable read
via pg_stat_wal_receiver and fix the error.

Also this commit moved the read of writtenUpto after the release
of spinlock protecting walreceiver's shared variables. This is
necessary to prevent new spinlock from being taken by atomic
variable read while holding another spinlock, and to shorten
the spinlock duration. This change leads writtenUpto not to be
consistent with the other walreceiver's shared variables protected
by a spinlock. But this is OK because writtenUpto should not be
used for data integrity checks.

Back-patch to v13 where commit 2c8dd05d6c introduced the bug.

Author: Fujii Masao
Reviewed-by: Michael Paquier, Thomas Munro, Andres Freund
Discussion: https://postgr.es/m/7ef8708c-5b6b-edd3-2cf2-7783f1c7c175@oss.nttdata.com
2021-02-18 23:28:15 +09:00
..
access nbtree README: move VACUUM linear scan section. 2021-02-17 21:13:15 -08:00
bootstrap Update copyright for 2021 2021-01-02 13:06:25 -05:00
catalog Routine usage information schema tables 2021-02-17 18:16:06 +01:00
commands Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
executor Fix tuple routing to initialize batching only for inserts 2021-02-18 00:03:45 +01:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
lib Update copyright for 2021 2021-01-02 13:06:25 -05:00
libpq Allow specifying CRL directory 2021-02-18 07:59:10 +01:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Remove [Merge]AppendPath.partitioned_rels. 2021-02-01 14:43:54 -05:00
optimizer Remove [Merge]AppendPath.partitioned_rels. 2021-02-01 14:43:54 -05:00
parser Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
partitioning Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
po Translation updates 2020-05-18 12:49:30 +02:00
port Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
postmaster Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
regex Make some minor improvements in the regex code. 2021-02-17 12:24:23 -05:00
replication Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver. 2021-02-18 23:28:15 +09:00
rewrite Revert "Propagate CTE property flags when copying a CTE list into a rule." 2021-02-07 12:54:08 -05:00
snowball Update copyright for 2021 2021-01-02 13:06:25 -05:00
statistics Update copyright for 2021 2021-01-02 13:06:25 -05:00
storage Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
tcop Use errmsg_internal for debug messages 2021-02-17 11:33:25 +01:00
tsearch Fix parsing of complex morphs to tsquery 2021-01-31 20:14:29 +03:00
utils Allow specifying CRL directory 2021-02-18 07:59:10 +01:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Update copyright for 2021 2021-01-02 13:06:25 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Add missing gettext triggers 2020-04-28 13:35:40 +02:00