diff options
author | Noah Misch <noah@leadboat.com> | 2025-04-17 05:00:30 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2025-04-17 05:00:30 -0700 |
commit | f4ece891fc2f3f96f0571720a1ae30db8030681b (patch) | |
tree | 61437530ceb8f305390574162aa6903cd057f0e6 /src/include/storage | |
parent | b669293e3432ee8fdcd44854a945837bb18eea5c (diff) | |
download | postgresql-f4ece891fc2f3f96f0571720a1ae30db8030681b.tar.gz postgresql-f4ece891fc2f3f96f0571720a1ae30db8030681b.zip |
Assert lack of hazardous buffer locks before possible catalog read.
Commit 0bada39c83a150079567a6e97b1a25a198f30ea3 fixed a bug of this kind,
which existed in all branches for six days before detection. While the
probability of reaching the trouble was low, the disruption was extreme. No
new backends could start, and service restoration needed an immediate
shutdown. Hence, add this to catch the next bug like it.
The new check in RelationIdGetRelation() suffices to make autovacuum detect
the bug in commit 243e9b40f1b2dd09d6e5bf91ebf6e822a2cd3704 that led to commit
0bada39. This also checks in a number of similar places. It replaces each
Assert(IsTransactionState()) that pertained to a conditional catalog read.
No back-patch for now, but a back-patch of commit 243e9b4 should back-patch
this, too. A back-patch could omit the src/test/regress changes, since back
branches won't gain new index columns.
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Discussion: https://postgr.es/m/20250410191830.0e.nmisch@google.com
Discussion: https://postgr.es/m/10ec0bc3-5933-1189-6bb8-5dec4114558e@gmail.com
Diffstat (limited to 'src/include/storage')
-rw-r--r-- | src/include/storage/bufmgr.h | 3 | ||||
-rw-r--r-- | src/include/storage/lwlock.h | 2 |
2 files changed, 5 insertions, 0 deletions
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index 33a8b8c06fb..41fdc1e7693 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -258,6 +258,9 @@ extern Buffer ExtendBufferedRelTo(BufferManagerRelation bmr, extern void InitBufferManagerAccess(void); extern void AtEOXact_Buffers(bool isCommit); +#ifdef USE_ASSERT_CHECKING +extern void AssertBufferLocksPermitCatalogRead(void); +#endif extern char *DebugPrintBufferRefcount(Buffer buffer); extern void CheckPointBuffers(int flags); extern BlockNumber BufferGetBlockNumber(Buffer buffer); diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index 70d386cf0e0..2b4cbda39a5 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -131,6 +131,8 @@ extern void LWLockReleaseClearVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 extern void LWLockReleaseAll(void); extern void LWLockDisown(LWLock *lock); extern void LWLockReleaseDisowned(LWLock *lock, LWLockMode mode); +extern void ForEachLWLockHeldByMe(void (*callback) (LWLock *, LWLockMode, void *), + void *context); extern bool LWLockHeldByMe(LWLock *lock); extern bool LWLockAnyHeldByMe(LWLock *lock, int nlocks, size_t stride); extern bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode); |