1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-27 22:56:53 +03:00

Don't allow GetTransactionSnapshot() in logical decoding

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
This commit is contained in:
Heikki Linnakangas 2024-12-23 12:42:55 +02:00
parent 952365cded
commit 1585ff7387

View File

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