mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Prevent concurrent SimpleLruTruncate() for any given SLRU.
The SimpleLruTruncate() header comment states the new coding rule. To achieve this, add locktype "frozenid" and two LWLocks. This closes a rare opportunity for data loss, which manifested as "apparent wraparound" or "could not access status of transaction" errors. Data loss is more likely in pg_multixact, due to released branches' thin margin between multiStopLimit and multiWrapLimit. If a user's physical replication primary logged ": apparent wraparound" messages, the user should rebuild standbys of that primary regardless of symptoms. At less risk is a cluster having emitted "not accepting commands" errors or "must be vacuumed" warnings at some point. One can test a cluster for this data loss by running VACUUM FREEZE in every database. Back-patch to 9.5 (all supported versions). Discussion: https://postgr.es/m/20190218073103.GA1434723@rfd.leadboat.com
This commit is contained in:
@@ -59,6 +59,9 @@ extern bool ConditionalLockRelationForExtension(Relation relation,
|
||||
LOCKMODE lockmode);
|
||||
extern int RelationExtensionLockWaiterCount(Relation relation);
|
||||
|
||||
/* Lock to recompute pg_database.datfrozenxid in the current database */
|
||||
extern void LockDatabaseFrozenIds(LOCKMODE lockmode);
|
||||
|
||||
/* Lock a page (currently only used within indexes) */
|
||||
extern void LockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
||||
extern bool ConditionalLockPage(Relation relation, BlockNumber blkno, LOCKMODE lockmode);
|
||||
|
@@ -139,6 +139,7 @@ typedef enum LockTagType
|
||||
{
|
||||
LOCKTAG_RELATION, /* whole relation */
|
||||
LOCKTAG_RELATION_EXTEND, /* the right to extend a relation */
|
||||
LOCKTAG_DATABASE_FROZEN_IDS, /* pg_database.datfrozenxid */
|
||||
LOCKTAG_PAGE, /* one page of a relation */
|
||||
LOCKTAG_TUPLE, /* one physical tuple */
|
||||
LOCKTAG_TRANSACTION, /* transaction (for waiting for xact done) */
|
||||
@@ -195,6 +196,15 @@ typedef struct LOCKTAG
|
||||
(locktag).locktag_type = LOCKTAG_RELATION_EXTEND, \
|
||||
(locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
|
||||
|
||||
/* ID info for frozen IDs is DB OID */
|
||||
#define SET_LOCKTAG_DATABASE_FROZEN_IDS(locktag,dboid) \
|
||||
((locktag).locktag_field1 = (dboid), \
|
||||
(locktag).locktag_field2 = 0, \
|
||||
(locktag).locktag_field3 = 0, \
|
||||
(locktag).locktag_field4 = 0, \
|
||||
(locktag).locktag_type = LOCKTAG_DATABASE_FROZEN_IDS, \
|
||||
(locktag).locktag_lockmethodid = DEFAULT_LOCKMETHOD)
|
||||
|
||||
/* ID info for a page is RELATION info + BlockNumber */
|
||||
#define SET_LOCKTAG_PAGE(locktag,dboid,reloid,blocknum) \
|
||||
((locktag).locktag_field1 = (dboid), \
|
||||
|
Reference in New Issue
Block a user