Suppose a data engineer exports orders and order lines from PostgreSQL into a warehouse each morning. Finance uses the warehouse to reconcile booked revenue. In this hypothetical pipeline, the application creates an order and its lines in one transaction, but the extraction job reads the two tables separately.
An order commits between those reads. The orders file excludes it; the order-lines file includes it. Both queries succeeded, yet finance receives lines without a matching order. I would give the related extracts one database snapshot and publish them as one completed batch.
PostgreSQL’s default Read Committed isolation gives each statement its own snapshot. Wrapping both queries in an ordinary transaction does not prevent this mismatch. A concurrent commit can become visible to the second query.
For a modest export, I would start with one connection and an explicit read-only Repeatable Read transaction. Its queries share the snapshot established by the first non-transaction-control statement. This illustrative SQL has not been tested against a deployment; the extraction client must stream each result into its corresponding staged file:
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY;
SELECT order_id, customer_id, total_amount
FROM orders;
SELECT order_id, line_id, quantity, unit_price
FROM order_lines;
COMMIT;
The example assumes ordinary tables in one database and an extraction role that can see all required rows. It also depends on the application committing each order and its lines together. A stable snapshot can preserve an intermediate business state if the application writes related records in separate transactions.
Parallel extraction needs additional coordination. Giving every worker Repeatable Read independently still allows different snapshots. PostgreSQL provides snapshot export and import for sessions that need the same view. A coordinator calls pg_export_snapshot() and passes the returned identifier to the workers.
Each worker starts its transaction with the required isolation level and imports that identifier using SET TRANSACTION SNAPSHOT, before its first query. The coordinator must remain open until all workers have imported the snapshot. I would require an explicit acknowledgement from each worker before releasing it.
That lifetime shapes retry behavior. If a worker loses its connection after the coordinator closes, a replacement cannot import the old snapshot. Retrying only the failed table against current data would recreate the opening defect. For this daily export, I would discard the incomplete batch and restart all related extracts with a new snapshot. Keeping the coordinator alive through possible retries is another choice, with a longer transaction as its cost.
Long snapshots deserve an operational limit. PostgreSQL’s vacuum documentation explains that old row versions remain while transactions may still need them. A slow export can delay cleanup of those versions. Set a maximum batch duration, monitor transaction age, and close abandoned sessions.
The warehouse still needs its own publication boundary. Stage both files under one batch ID, validate their relationship, and expose the completed batch together. A consistent source read cannot prevent consumers from seeing half a warehouse load.
Before releasing this pipeline, pause extraction between the two reads and commit a new order with its lines. Verify that the completed batch contains both or neither. Then break a worker connection and inspect recovery. Finance should receive a coherent batch with a visible extraction time, even when that means waiting for a complete rerun.