Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27f2044

Browse files
committed
Revert GetTransactionSnapshot() to return historic snapshot during LR
Commit1585ff7 changed GetTransactionSnapshot() to throw an errorif it's called during logical decoding, instead of returning thehistoric snapshot. I made that change for extra protection, because ahistoric snapshot can only be used to access catalog tables whileGetTransactionSnapshot() is usually called when you're executingarbitrary queries. You might get very subtle visibility problems ifyou tried to use the historic snapshot for arbitrary queries.There's no built-in code in PostgreSQL that callsGetTransactionSnapshot() during logical decoding, but it turns outthat the pglogical extension does just that, to evaluate row filterexpressions. You would get weird results if the row filter runsarbitrary queries, but it is sane as long as you don't access anynon-catalog tables. Even though there are no checks to enforce that inpglogical, a typical row filter expression does not access any tablesand works fine. Accessing tables marked with the user_catalog_table =true option is also OK.To fix pglogical with row filters, and any other extensions that mightdo similar things, revert GetTransactionSnapshot() to return ahistoric snapshot during logical decoding.To try to still catch the unsafe usage of historic snapshots, addchecks in heap_beginscan() and index_beginscan() to complain if youtry to use a historic snapshot to scan a non-catalog table. We're veryclose to the version 18 release however, so add those new checks onlyin master.Backpatch-through: 18Reported-by: Noah Misch <noah@leadboat.com>Reviewed-by: Noah Misch <noah@leadboat.com>Discussion:https://www.postgresql.org/message-id/20250809222338.cc.nmisch@google.com
1 parentfc38714 commit27f2044

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

‎src/backend/utils/time/snapmgr.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,23 @@ Snapshot
271271
GetTransactionSnapshot(void)
272272
{
273273
/*
274-
* This should not be called while doing logical decoding. Historic
275-
* snapshots are only usable for catalog access, not for general-purpose
276-
* queries.
274+
* Return historic snapshot if doing logical decoding.
275+
*
276+
* Historic snapshots are only usable for catalog access, not for
277+
* general-purpose queries. The caller is responsible for ensuring that
278+
* the snapshot is used correctly! (PostgreSQL code never calls this
279+
* during logical decoding, but extensions can do it.)
277280
*/
278281
if (HistoricSnapshotActive())
279-
elog(ERROR,"cannot take query snapshot during logical decoding");
282+
{
283+
/*
284+
* We'll never need a non-historic transaction snapshot in this
285+
* (sub-)transaction, so there's no need to be careful to set one up
286+
* for later calls to GetTransactionSnapshot().
287+
*/
288+
Assert(!FirstSnapshotSet);
289+
returnHistoricSnapshot;
290+
}
280291

281292
/* First call in transaction? */
282293
if (!FirstSnapshotSet)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp