Choose PostgreSQL extraction by the changes you need to preserve
In brief
Snapshot bounded PostgreSQL datasets when only current state matters. Use CDC when consumers need changes between snapshots.
- Poll timestamps only if every write updates them and you can account for late commits and deletions.
- Test CDC restart and replay from a known position.
For a small dataset that only needs to reflect current PostgreSQL state on a schedule, we’d start with a complete, consistent snapshot.
Load a new generation, validate it, and replace the previous source-owned state with it. That’s often easier to inspect and recover than a connector maintaining a continuous position.
Choose a different method when the required changes won’t survive that approach. A stock record that goes from available to unavailable and back between exports leaves no evidence in either snapshot. If the business needs those transitions, a more frequent snapshot only narrows the window in which they disappear. The decision starts with the source changes the model must observe, the delay it can tolerate, and the work needed to keep that observation reliable. Table size and advertised connector latency come after those three.
Decide whether you’re copying state or keeping changes
A current inventory table might need the latest quantity for each warehouse and product. If a quantity changes three times between refreshes, the next complete state is enough. A model of stockout intervals reading the same table needs evidence of the changes in between.
Before choosing a tool, write a small transition sequence: insert a record, update it, delete it, recreate the same key, and update it twice between scheduled reads. Add a source correction with an old business date and a transaction that commits later than another transaction started after it. Which observations does the consumer need?
A complete snapshot shows the rows that survive at its source boundary. Comparing authoritative snapshots can identify keys that disappeared, but it can’t reconstruct a row created and deleted entirely between them. Timestamp polling finds surviving changed rows only when every mutation maintains the field and stays inside what the polling query selects. A change feed can keep operations that no longer exist in the current table, within the limits of what its source, filters, and connector emit.
Keeping yesterday’s copy doesn’t turn a current-state replica into an event history. If the source never recorded the distinction the business needs, no extraction method can invent it.
Keep the snapshot default while a full read is affordable
Measure the full extraction at the required cadence: source work, transfer, target load, and the time before a validated generation becomes available.
A complete refresh that comfortably fits those constraints is also easy to recover. After a failed run, another complete read restores current state without reconstructing every missed update.
The snapshot must describe one consistent source view. At PostgreSQL’s default Read Committed level, separate queries can observe different committed states. A multi-query extract needs one transaction with a stable snapshot, and parallel workers that need cross-table consistency must share a snapshot. Starting several Repeatable Read transactions independently doesn’t give them the same snapshot.
Completeness also includes scope. A filtered or partially authorized export can’t justify removing every target key absent from it. Keep the declared population and evidence that extraction completed before replacing that population. An empty but successful export and an interrupted export that produced no rows must have different outcomes.
The default changes when reading the whole population costs too much, the refresh can’t finish within the required delay, or required intermediate changes vanish between reads. Add change capture once you’ve observed one of those. A table size you don’t have yet doesn’t count.
Timestamp polling needs more than an index
A polling query usually looks harmless: select rows whose update timestamp is greater than the last accepted timestamp. It can be enough when every write maintains that timestamp, deletions leave evidence, and there’s a bounded way to revisit changes that become visible late.
Inspect every write path first. An application timestamp that a bulk import skips doesn’t describe all mutations. A business effective date isn’t a modification timestamp.
A hard-deleted row no longer exists for the next query to return. To see deletions, polling needs soft-deletion markers that stay in the table, a separate deletion feed, or an authoritative periodic comparison to repair missing keys.
Ties are another problem. If a page ends halfway through rows sharing one timestamp, advancing beyond that timestamp skips the rest. Pairing the timestamp with a stable key orders the visible rows:
WHERE (updated_at, id) > (:last_timestamp, :last_id)
ORDER BY updated_at, id
LIMIT :page_sizeThis cursor only orders rows that are already visible. It assumes defined fields and null behavior and a stable boundary for traversal. Mutable rows can still move while pages are read. Worse, a transaction can become visible after the cursor has already passed its timestamp.
A later commit can fall behind the watermark
Consider two transactions on different rows. Transaction A starts at 09:00 and records updated_at = CURRENT_TIMESTAMP, but stays open. B starts at 09:01 and commits. At 09:02, the extractor sees B and saves its 09:01 timestamp. A commits at 09:03 with its earlier timestamp, and the next query for values greater than 09:01 never returns A.
Two behaviors cause this. Queries don’t see another transaction’s uncommitted rows, and in PostgreSQL CURRENT_TIMESTAMP is the transaction start time. The database clock doesn’t turn the value into commit order, because even a timestamp taken when the row is written can precede a delayed commit.
A monotonically allocated ID has the same visibility problem. A transaction can obtain the lower sequence value and commit after a transaction holding a higher one. PostgreSQL sequence allocation doesn’t serialize the transactions that consume those values. Adding the ID as a timestamp tie-breaker fixes ties but not this missing row.
A lookback window can repair the hole when you know how far behind the watermark a newly visible modification can fall. That bound has to cover transaction duration, clock behavior, and any backdated or bulk writes the application allows.
Re-read the overlap and apply rows idempotently. Choose the window from evidence and monitor violations, or “we look back a few minutes” becomes an undocumented loss policy.
If you can’t prove that bound, keep periodic complete reconciliation or choose capture that gives you a change position you can trust.
A larger arbitrary window misses fewer rows, but you still can’t say it misses none. Intermediate updates also disappear whenever later state overwrites them before the next poll.
CDC buys a change stream and creates a recovery obligation
Log-based capture reads PostgreSQL’s write-ahead log through logical decoding. It can expose committed row changes without every application writer maintaining a polling timestamp.
We’d choose it when repeated current-state reads can’t keep up with hard deletes, intervening updates, or extraction volume.
Verify what the capture path emits. With PostgreSQL publications, operation selection and replica identity affect which changes can be replicated. Updates and deletes need usable row identity. Check what the connector does on key changes, truncation, large values, filtered tables, and schema changes.
Native logical replication also doesn’t replicate DDL. An ingestion connector may handle schema discovery separately. Check how it does that before relying on the row stream to carry schema changes.
A row change isn’t a business event either: a status update isn’t automatically a durable “order approved” event.
The operating work includes a correct handoff from the initial snapshot to the stream, durable progress, replay-safe application, history retention, and recovery when the saved position is gone. Logical decoding can deliver changes again after a crash. Replication slots keep source resources until their consumer confirms progress.
Monitor how much WAL the source keeps and how far the consumer has progressed. Decide who responds when consumption stops.
CDC doesn’t force every downstream model to run continuously. A connector can land the stream while the warehouse publishes validated batches on the schedule consumers need. Keep that separation when continuous target mutation would add complexity without improving the result.
Replay the transition sequence before adopting a method
Run the transition sequence you wrote earlier through the proposed capture path, and compare what arrives with what the consumer needs. Repeat it with an interrupted extraction, then pause consumption in an isolated test environment long enough to exercise the documented recovery procedure.
Each method also has its own failure to provoke. For polling, commit a lower timestamp or sequence after a higher one has been accepted. For snapshots, check that a partial generation never replaces complete state. For CDC, check the bootstrap boundary, duplicate handling, and what happens when the source no longer holds the history needed to bridge an outage.
If polling needs several undocumented exceptions to explain why it won’t miss a change, it’s no longer the simple option. Count its recovery work in the comparison too.
More in this domain: Data
Browse allWhen cold history should stay in BigQuery
Keep cold history in BigQuery when retrieval costs would outweigh the storage savings.
BigQuery global queries or a local serving copy?
A global BigQuery query can suit occasional selective reads. An approved local copy can save transfers when reports repeatedly read the same remote data.
Use BigQuery clones for bounded development work
Use a writable BigQuery clone when a test needs the source data's distribution or history. Use a small fixture when it reproduces the problem.
When external Parquet deserves a native BigQuery copy
Keep Parquet external for occasional reads. A native BigQuery copy can pay off when reports repeatedly scan the same files.
Publish a BigQuery dataset without sponsoring every reader's queries
Publish a BigQuery dataset when readers need SQL and have their own execution project. Offer versioned downloads for readers who just need the data.
Related patterns
Reconcile source and warehouse data without trusting matching totals
Reconcile the same population at the same source cutoff using controls computed independently of the warehouse load.
When selective lookups can stay in BigQuery
Try a BigQuery search index for occasional, selective lookups on data already in the warehouse.
BigQuery tenant access starts with the query identity
Choose tenant isolation from the identity BigQuery sees on the report's query.
BigQuery physical vs. logical storage: compare the full bill
Physical billing rewards compression, but retained versions can consume the savings. Compare both models using the dataset's current data, rewrite history, and recovery requirements.