Skip to content

Commit 7da8341

Browse files
committed
Revive "snapshot too old" with wal_level=minimal and SET TABLESPACE.
Given a permanent relation rewritten in the current transaction, the old_snapshot_threshold mechanism assumed the relation had never been subject to early pruning. Hence, a query could fail to report "snapshot too old" when the rewrite followed an early truncation. ALTER TABLE SET TABLESPACE is probably the only rewrite mechanism capable of exposing this bug. REINDEX sets indcheckxmin, avoiding the problem. CLUSTER has zeroed page LSNs since before old_snapshot_threshold existed, so old_snapshot_threshold has never cooperated with it. ALTER TABLE ... SET DATA TYPE makes the table look empty to every past snapshot, which is strictly worse. Back-patch to v13, where commit c6b9204 broke this. Kyotaro Horiguchi and Noah Misch Discussion: https://postgr.es/m/20210113.160705.2225256954956139776.horikyota.ntt@gmail.com
1 parent 360bd23 commit 7da8341

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/backend/utils/time/snapmgr.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,11 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin,
17641764
Assert(OldSnapshotThresholdActive());
17651765
Assert(limit_ts != NULL && limit_xid != NULL);
17661766

1767-
if (!RelationAllowsEarlyPruning(relation))
1767+
/*
1768+
* TestForOldSnapshot() assumes early pruning advances the page LSN, so we
1769+
* can't prune early when skipping WAL.
1770+
*/
1771+
if (!RelationAllowsEarlyPruning(relation) || !RelationNeedsWAL(relation))
17681772
return false;
17691773

17701774
ts = GetSnapshotCurrentTimestamp();

src/include/utils/snapmgr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
#define RelationAllowsEarlyPruning(rel) \
3939
( \
40-
RelationNeedsWAL(rel) \
40+
(rel)->rd_rel->relpersistence == RELPERSISTENCE_PERMANENT \
4141
&& !IsCatalogRelation(rel) \
4242
&& !RelationIsAccessibleInLogicalDecoding(rel) \
4343
)

0 commit comments

Comments
 (0)