Don't allow GetTransactionSnapshot() in logical decoding
authorHeikki Linnakangas <[email protected]>
Mon, 23 Dec 2024 10:42:55 +0000 (12:42 +0200)
committerHeikki Linnakangas <[email protected]>
Mon, 23 Dec 2024 10:42:55 +0000 (12:42 +0200)
A historic snapshot should only be used for catalog access, not
general queries. We never call GetTransactionSnapshot() during logical
decoding, which is good because it wouldn't be very sensible, so the
code to deal with that was unreachable and untested. Turn it into an
error, to avoid doing that in the future either.

Discussion: https://www.postgresql.org/message-id/a868fe78-ddb4-4b0a-9b96-873d91d93cfd@iki.fi

src/backend/utils/time/snapmgr.c

index e002d0c1368d22eb0929765c8059901c7d7ac50c..6eb29b9973541f81c3d9f16befc5dc935dbf8b34 100644 (file)
@@ -212,16 +212,12 @@ Snapshot
 GetTransactionSnapshot(void)
 {
    /*
-    * Return historic snapshot if doing logical decoding. We'll never need a
-    * non-historic transaction snapshot in this (sub-)transaction, so there's
-    * no need to be careful to set one up for later calls to
-    * GetTransactionSnapshot().
+    * This should not be called while doing logical decoding.  Historic
+    * snapshots are only usable for catalog access, not for general-purpose
+    * queries.
     */
    if (HistoricSnapshotActive())
-   {
-       Assert(!FirstSnapshotSet);
-       return HistoricSnapshot;
-   }
+       elog(ERROR, "cannot take query snapshot during logical decoding");
 
    /* First call in transaction? */
    if (!FirstSnapshotSet)