Skip to main content
A replica reads a database’s own change log through a SQL change receiver (@bijectionhq/app-sql) or a Debezium envelope receiver. A SQL replica lands each complete source commit and its position in one Bijection transaction. A source transaction too large for one Bijection transaction stops the replica before publishing any of that commit (large source transactions). See dialects for declared source protocols. For Oracle, see the Oracle Database relation source.

Declare and place the replica

replica(dialect, { tables, groups? }) from @bijectionhq/library-replicas declares each replicated table, its source table, its key and its projected columns. Calling the declaration with { provider, allow, label?, lag? } returns a subtree you place directly in app(...) — its tree path in the app tree is its name:
bijection/warehouse.ts
  • source is schema.name; for envelope it is the Kafka topic carrying the table’s change envelopes.
  • key is the primary key, or the columns of a unique not-null index, in order. A keyless table cannot be replicated: read it with a periodic poll instead.
  • fields maps each projected source column to its value type. Key columns are never t.maybe. Unlisted columns are not read.
  • label (optional) is the label every replicated row carries.
  • index (optional) declares field orders beside key; the key is always a point.
  • groups lists tables that stop together.
Set the SQL replica’s retention budget with hold on its receiver. Envelope replicas take hold and onHold on the mount.

Read the tables

In an application query, call warehouse.read(ctx) to read SQL tables at one published source position in the query’s frame. Use get with the full declared key, where(...).first(n) with equality on a declared index, or first(n) for a bounded scan in fact-ID order.
bijection/app.ts
SQL reads return ReplicaUnavailable during initial baselining or any rebuild, after a source gap, or at a replica-wide stop. Reading an individual stopped table also returns ReplicaUnavailable. Every read enforces the declared row label. The private tables are written through sync.writes, so application queries and direct operator writes cannot bypass selection. Envelope replicas expose ordinary keyed tables through table.readOnly(...). Read those with ctx.get and ctx.list. Keep application-owned annotations in separate tables.

Credentials and source setup

No bindings entry is required. Store the receiver’s login secret at its tree path:
After deploying, run bijection mutate warehouse.inspect to submit a read-only probe against the source. bijection query warehouse.status then shows its result: any missing settings, privileges or setup SQL, and the keys and fields the source catalog declares for each table. Bijection never runs that SQL and never creates tables, triggers or schemas in your database. Run it as the source administrator.

What happens next

The SQL replica builds its baseline in bounded key ranges and replays the source log before selecting a cut. bijection query warehouse.status reads the mounted warehouse.status query: its state, lag, hold and table states.

PostgreSQL capture through Debezium

exactReplica follows a dedicated PostgreSQL capture enrollment. The worker takes an exported snapshot, seals committed changes and its restart offset together, and answers the installation’s signed replication target. The replica prepares immutable row and index pages in bounded batches. It publishes a snapshot or complete source transaction by selecting its manifest and cut together in one local transaction. Readers keep using the previous manifest until selection commits. Unchanged pages are shared by the two manifests. Worker and gateway setup Each exact replica defaults to 1 GiB of charged live page storage and 4,000,000 page, reference and cleanup obligations. Set storage.bytes and storage.obligations on exactReplica to size the mount. Allow room for the selected snapshot, its replacement and any pages still awaiting collection. shop.status reports the charge and limits. When collection can make room, capture pauses with ReplicaStorageCapacity and retries the same page as capacity frees up. If the candidate still cannot fit, capture blocks with that reason and keeps serving the selected cut. The replica credits page capacity when it deletes the unreachable pages and releases their child references. A reader admitted to a held Store version still sees its original manifest and pages. Store history and physical erasure follow their own retention and custody rules. The provider can pack consecutive small commits into one page. A truncate clears the affected table’s roots within the same publication. The other tables keep their roots. An expired transaction candidate can retry from the selected cut while the source journal retains its pages. If the provider reports a retention gap, the replica keeps serving its last published cut. An explicit rebaseline can select a new snapshot.
bijection/app.ts
Select the enrolled source in the installation’s bindings file, the file you pass to bijection deploy --bindings <file>. The source is a resource entry: it chooses which database the replica reads, and each installation’s file can name its own.
Before deploying, approve the source and its recipient grant with bijection capture enroll. The grant names the installation, source alias, receiver, label and typed projection. Approval is authority to read the source; it does not choose who operates capture. Who runs the capture worker is placement. The replica’s capture slot (exact-capture@1), here shop.capture, is managed unless you bind it: the cell creates a managed worker when an installed release requests the source. Deployment checks and records the approved source revision. The app can serve its other functions while capture is taking its first snapshot. Replica reads return ReplicaUnready until its first snapshot is selected. A dry run checks the declaration and the capture slot’s placement. Each live delivery checks the enrollment again, and the worker verifies the projection independently. Set observeHead: true on the replica to sample the source WAL head. A query can then use shop.read(ctx, { freshWithin: { seconds: 10 } }). It receives ReplicaStale if the published cut falls behind the observation or the observation has expired. The mounted shop.cut query takes freshWithin as a Temporal duration. Freshness is measured from when Bijection started the capture request that supplied the latest observed head. The evidence expires at that time plus the specified duration. Specify whole milliseconds from 1 millisecond through 24 hours, with a day counting as 24 hours. An unreachable source supplies no new freshness evidence. The two local reads share the query’s frame. The mounted operator functions are shop.status, shop.inspect, shop.pause, shop.resume and shop.rebaseline. Pass acceptNewHistory=false to rebaseline against the same source history. A manual pause discards unfinished staging and leaves the selected cut readable. Resume restarts an unfinished snapshot with a new generation or requests changes from the selected cut. A replacement provider or source with a different history needs a reviewed acceptNewHistory=true call. To first deploy with your own Debezium provider, enroll the source as external. Put the network and credential references in that enrollment. Keep the source alias in the resource bindings above. Put the capture provider in the installation’s provider map and pass that file with bijection deploy --bindings <file>.
placement.bindings.ts
Choose the operator before the first deployment of the capture slot. Live handoff between managed and customer providers still requires capture lifecycle support. shop.status includes the published cut and pages staged during a multi-page transaction. A managed capture placement reports usage per source. The installation that enrolled a shared source pays for it.