Repository navigation
Read the postgis lookup without asking for a transaction id - #297
Merged
aykut-bozkurt merged 1 commit intoNov 4, 2026
Merged
aykut-bozkurt merged 1 commit into
aykut-bozkurt merged 1 commit into
Conversation
A parallel COPY TO failed outright when postgis is installed: SET pg_parquet.max_parallel_workers TO 4; COPY a_table TO '/tmp/out.parquet'; ERROR: cannot assign transaction IDs during a parallel operation The startup of every copy looks the postgis extension up, and the lookups went through pgrx's Spi::get_one, which takes the mutable path: it tells postgres the transaction is about to write by asking it for a transaction id. A parallel worker cannot be given one, so the worker that ran the lookup failed the copy. The lookups only read, so they are read through Spi::connect instead, the way the profile mapping already is. A transaction that has already written holds an id, and the lookup is answered out of the one it holds, which is why the tests did not catch this: pgrx runs a test inside a transaction that created and filled the table it copies. The copy is the first thing an ordinary transaction does, so it holds no id, and every parallel COPY TO in such a transaction was refused. A copy with no postgis installed was unaffected, since the lookup reads nothing then. The test runs the copy in a database and a session of its own, so that postgis is installed and the transaction the copy runs in has written nothing. It leaves the database behind rather than dropping it, since DROP DATABASE waits for every backend to take a procsignal barrier and the backend running the test is blocked on psql, so it would wait for itself. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
aykut-bozkurt
approved these changes
Nov 4, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #297 +/- ##
========================================
Coverage 94.77% 94.77%
========================================
Files 123 124 +1
Lines 25842 26016 +174
========================================
+ Hits 24491 24657 +166
- Misses 1351 1359 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A parallel
COPY TOfails outright when PostGIS is installed:No destination is written. It is not specific to a destination, an option or a column type: a
plain
COPY <table> TO '<file>'in a fresh transaction is enough, on a table large enough forthe copy to be split into ctid ranges.
The startup of every copy looks the PostGIS extension up, and those lookups went through pgrx's
Spi::get_one, which takes the mutable path: it tells PostgreSQL the transaction is about towrite by asking it for a transaction id. A parallel worker cannot be given one, so the worker
that ran the lookup failed the copy.
Two things hid it:
out of the one it holds rather than assigning a new one. pgrx runs every test inside a
transaction that created and filled the table it copies, so no test in
parallel_copy_to.rscould reach the failure. An ordinary
COPY TOis the first thing its transaction does, holdsno id, and was refused.
Solution
Read the lookups through
Spi::connect, which is read only, the way the profile mapping insrc/object_store/profile.rsalready is. Aread_onehelper holds the one call so the fourlookups cannot drift apart:
Test plan
test_parallel_copy_to_without_a_transaction_idruns the copy in a database and a session ofits own, so that PostGIS is installed, as it has to be for the lookup to read anything, and the
transaction the copy runs in has written nothing. It then reads the file back and counts the
rows, so a copy that succeeds at nothing does not pass.
It fails on this branch's parent with the production error and passes with the fix:
The test leaves its database behind rather than dropping it.
DROP DATABASEwaits for everybackend to take a procsignal barrier, and the backend running the test is blocked on psql, so it
would wait for itself. The test instance is thrown away with its data directory.
Also ran
copy_geospatial(37),copy_type_roundtrip(108),copy_options(61) andcreate_table_fromgreen, and checked by hand that a geometry and a geography column stillround-trip and that a parallel copy of a geometry table in a fresh transaction now succeeds.
🤖 Generated with Claude Code