Prevent "snapshot too old" from trying to return pruned TOAST tuples.
authorRobert Haas <rhaas@postgresql.org>
Wed, 3 Aug 2016 20:41:43 +0000 (16:41 -0400)
committerRobert Haas <rhaas@postgresql.org>
Wed, 3 Aug 2016 20:50:01 +0000 (16:50 -0400)
Previously, we tested for MVCC snapshots to see whether they were too
old, but not TOAST snapshots, which can lead to complaints about missing
TOAST chunks if those chunks are subject to early pruning.  Ideally,
the threshold lsn and timestamp for a TOAST snapshot would be that of
the corresponding MVCC snapshot, but since we have no way of deciding
which MVCC snapshot was used to fetch the TOAST pointer, use the oldest
active or registered snapshot instead.

Reported by Andres Freund, who also sketched out what the fix should
look like.  Patch by me, reviewed by Amit Kapila.

src/backend/access/heap/tuptoaster.c
src/backend/utils/time/snapmgr.c
src/backend/utils/time/tqual.c
src/include/storage/bufmgr.h
src/include/utils/snapmgr.h
src/include/utils/tqual.h

index 4cffd21d180e373309b11df85b7f0c74074df950..55b6b41f8c7fe9068000e660582de29c2837ed5b 100644 (file)
@@ -40,6 +40,7 @@
 #include "utils/expandeddatum.h"
 #include "utils/fmgroids.h"
 #include "utils/rel.h"
+#include "utils/snapmgr.h"
 #include "utils/typcache.h"
 #include "utils/tqual.h"
 
@@ -81,6 +82,7 @@ static int toast_open_indexes(Relation toastrel,
                   int *num_indexes);
 static void toast_close_indexes(Relation *toastidxs, int num_indexes,
                    LOCKMODE lock);
+static void init_toast_snapshot(Snapshot toast_snapshot);
 
 
 /* ----------
@@ -1665,6 +1667,7 @@ toast_delete_datum(Relation rel, Datum value)
    HeapTuple   toasttup;
    int         num_indexes;
    int         validIndex;
+   SnapshotData    SnapshotToast;
 
    if (!VARATT_IS_EXTERNAL_ONDISK(attr))
        return;