Skip to content

Commit 7932891

Browse files
committed
Ignore CatalogSnapshot when checking COPY FREEZE prerequisites.
This restores the ability, essentially lost in commit ffaa44c, to use COPY FREEZE under REPEATABLE READ isolation. Back-patch to 9.4, like that commit. Reviewed by Tom Lane. Discussion: https://postgr.es/m/CA+TgmoahWDm-7fperBxzU9uZ99LPMUmEpSXLTw9TmrOgzwnORw@mail.gmail.com
1 parent cf0612a commit 7932891

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/backend/commands/copy.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,13 +2317,25 @@ CopyFrom(CopyState cstate)
23172317
/*
23182318
* Optimize if new relfilenode was created in this subxact or one of its
23192319
* committed children and we won't see those rows later as part of an
2320-
* earlier scan or command. This ensures that if this subtransaction
2321-
* aborts then the frozen rows won't be visible after xact cleanup. Note
2320+
* earlier scan or command. The subxact test ensures that if this subxact
2321+
* aborts then the frozen rows won't be visible after xact cleanup. Note
23222322
* that the stronger test of exactly which subtransaction created it is
2323-
* crucial for correctness of this optimisation.
2323+
* crucial for correctness of this optimisation. The test for an earlier
2324+
* scan or command tolerates false negatives. FREEZE causes other sessions
2325+
* to see rows they would not see under MVCC, and a false negative merely
2326+
* spreads that anomaly to the current session.
23242327
*/
23252328
if (cstate->freeze)
23262329
{
2330+
/*
2331+
* Tolerate one registration for the benefit of FirstXactSnapshot.
2332+
* Scan-bearing queries generally create at least two registrations,
2333+
* though relying on that is fragile, as is ignoring ActiveSnapshot.
2334+
* Clear CatalogSnapshot to avoid counting its registration. We'll
2335+
* still detect ongoing catalog scans, each of which separately
2336+
* registers the snapshot it uses.
2337+
*/
2338+
InvalidateCatalogSnapshot();
23272339
if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
23282340
ereport(ERROR,
23292341
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),

src/backend/utils/time/snapmgr.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,14 @@ DeleteAllExportedSnapshotFiles(void)
14471447
FreeDir(s_dir);
14481448
}
14491449

1450+
/*
1451+
* ThereAreNoPriorRegisteredSnapshots
1452+
* Is the registered snapshot count less than or equal to one?
1453+
*
1454+
* Don't use this to settle important decisions. While zero registrations and
1455+
* no ActiveSnapshot would confirm a certain idleness, the system makes no
1456+
* guarantees about the significance of one registered snapshot.
1457+
*/
14501458
bool
14511459
ThereAreNoPriorRegisteredSnapshots(void)
14521460
{

0 commit comments

Comments
 (0)