DBTrail

Limitations

What DBTrail does not capture or rebuild on a PostgreSQL server, and where the copy answers differently from PostgreSQL.

Read this before you point DBTrail at production. In short:

  • UNLOGGED tables are not captured. PostgreSQL writes no change log for them.
  • A TRUNCATE is recorded, and cannot be undone. No row is kept for it.
  • Sequence positions are not captured. After a restore, run the sequence fix.
  • Which session made a change is not known. PostgreSQL does not send it.
  • One database per replication slot. Capture each database of a cluster as a server of its own.
  • One family of databases per installation. An installation that serves PostgreSQL serves only PostgreSQL.
  • A division on the copy has 16 decimals. Write round(a / b, k) to get PostgreSQL's exact text (why).

Check your own server

DBTrail's checks find the tables it would miss (UNLOGGED tables, a cascade child left out of the publication, a table not ready), on a machine with Docker:

docker run --rm --network host ghcr.io/dbtrail/bintrail-pg:latest doctor \
  --query-dsn "postgres://dbtrail:$DBTRAIL_PW@$PGHOST:${PGPORT:-5432}/$PGDATABASE" \
  --slot "bintrail_$PGDATABASE" --publication bintrail_pub

What each line means: Troubleshooting.

In detail

What DBTrail does not do on a PostgreSQL server, or does only in part. Read it before you point DBTrail at production.

Versions and installations

PostgreSQL 15 to 18 is supported (13 and 14 may work, best effort).

One database family per installation

An installation that serves PostgreSQL servers serves PostgreSQL servers only. The first server you add decides which family of databases an installation serves, and + Add server then offers that family's server types. A server of another family is refused with a message that says so, and nothing is changed.

PostgreSQL support and the support for other databases are tested and released apart and are never run together in one process, so the combination is not offered. This is about the databases DBTrail captures from: DBTrail's history store is the same for every family.

To capture another family of databases as well, run a second installation beside the first, in a folder with another name and on a port of its own:

curl -fsSL https://raw.githubusercontent.com/dbtrail/dbtrail/main/install.sh | DBTRAIL_DIR=./dbtrail-2 DBTRAIL_PORT=8091 sh

It has its own containers, its own index, and its own web interface and login on that port. The folder's name is what keeps the two apart, not its place: two folders that end in the same name (/opt/dbtrail and /srv/dbtrail) would share their data.

The ports the first installation holds are found taken. Metrics move to a free port by themselves. The PostgreSQL port (5433) is left unpublished: a second PostgreSQL installation adds a ports: line to its pg-router service (such as 127.0.0.1:5434:5433) and connects to that number.

If the servers file already holds both families (it was edited by hand, or comes from a version before this rule), nothing stops: every server is still captured and served, an error in the log names the servers, and a server can still be edited, which is how a changed password is put right. No server can be added until one family is left. Remove the servers of one family to get there.

Capture and recovery

  • UNLOGGED tables are not captured. They bypass the WAL by design, so logical decoding never sees them. bintrail-pg warns when an UNLOGGED table is in capture scope (at stream startup and in bintrail-pg doctor), under a FOR ALL TABLES publication and under a FOR TABLES IN SCHEMA (PostgreSQL 15+) publication's member schemas alike, but the changes are still not captured, so don't rely on bintrail for UNLOGGED data.
  • A cascade child must be in the publication. A foreign-key ON DELETE CASCADE / SET NULL is captured (PostgreSQL performs it as ordinary row changes) only if the child table is published. If a published parent has an unpublished cascade child, the cascade rewrites are not captured: bintrail-pg warns (startup
    • doctor); add the child to the publication.
  • TRUNCATE is recorded as an audit marker, not a reversible change. A PostgreSQL TRUNCATE emits no per-row DELETE, so left uncaptured it would be indistinguishable from "nothing happened". bintrail-pg records it as a schema_changes row (ddl_type = TRUNCATE TABLE): surfaced by the list_schema_changes MCP tool and in the schema_changes table. It is a record that the truncate happened, not a reversible event: recover has no per-row before-images to put back, and a reconstruct whose window crosses the truncate refuses instead of bringing the removed rows back. A multi-table TRUNCATE a, b records one marker per published table; a truncate of an out-of-scope table records nothing. All of this needs a publication that publishes truncate: without it PostgreSQL sends nothing and no marker is recorded (see step 4).
  • Other schema changes are inferred, not read. See Schema changes on PostgreSQL.
  • Sequence cursors are not captured. The materialized id values in your rows are captured; the sequence's own last_value (a separate catalog object) is not: logical decoding does not replicate sequences. After a restore, re-point each SERIAL/IDENTITY sequence past MAX(id): recipe and when it matters in Sequences after recovery.
  • GENERATED ... AS IDENTITY / generated columns can need care on recovery (GENERATED ALWAYS AS IDENTITY rejects an explicit insert; STORED generated columns are absent from the stream before PostgreSQL 18). Treat as best-effort. The copy never holds a generated column: the database computes it. On PostgreSQL 18 a table with a VIRTUAL generated column cannot be captured, and one with a STORED one needs publish_generated_columns = stored on the publication (PostgreSQL 18 and generated columns).
  • Full-table reconstruct writes snapshots (--output-format parquet, and baseline refresh) or SQL psql loads (--output-format psql) (see Full-table snapshots). bintrail-pg drill rehearses the restore into a scratch PostgreSQL from the psql files. verify is supported too: baseline-anchored, live-source, and recover-input modes are all supported for PostgreSQL sources (see Verify a recovery, including how the live-source coverage check differs). Single-row reconstruct and the shim's single-row _snapshot work against a PG baseline and are validated end-to-end for scalar types, including the GUC-sensitive set, rendered under session GUCs pinned identically at capture and baseline; container types remain best-effort (see Querying and recovering). (recover and recover-cascade work unconditionally, with no baseline needed; cascades are captured as ordinary row changes: see Querying and recovering.)
  • No connection attribution. pgoutput does not carry the backend PID, so the connection_id column is empty for PostgreSQL sources. Forensic attribution ("which session made this change") is therefore not available for PostgreSQL sources, and this is a settled decision, not a pending gap (#1212): the only way to recover the backend PID is to install something into your database, and bintrail installs nothing into a source. Everything else forensics offers (the full before/after row images, the change timeline, --query-hash grouping where the source logs statements) works identically on PostgreSQL.
  • A large transaction arrives whole, after it commits. PostgreSQL sends a transaction only once it has committed, and every change committed after it waits behind it. One that changed a few million rows can leave the copy minutes behind; it catches up by itself. What counts is how many rows it changed, not how long it stayed open. A job that changes rows in bulk keeps the copy close by committing in batches.
  • A partitioned table published through its parent (publish_via_partition_root): a change whose earlier row holds an empty (NULL) column is stored with its key only, and undo refuses that change. Nothing wrong is stored. A table that is not partitioned is not affected.
  • One database per slot. A logical slot is scoped to a single database; to capture multiple databases on one cluster, run one bintrail-pg stream (and slot/publication) per database.
  • No BYOS agent. The web interface captures PostgreSQL sources (+ Add server → PostgreSQL); bintrail agent (BYOS) does not support PostgreSQL.

The data-safety gates for PostgreSQL are closed (#597): the data-safety set (type fidelity, identity/generated recovery, slot/WAL monitoring, RI-FULL validation, DDL-drift handling, the silent-loss coverage guards above), baseline-anchored single-row reconstruct / time-travel with the baseline↔delta rendering-GUC identity and its fold-validated type matrix (#593), the managed-PostgreSQL smoke matrix (RDS and Aurora: see Managed PostgreSQL), and source-aware web interface presentation including the live replication-health panel (v0.20.1). Full-table reconstruct writes snapshots (--output-format parquet, and baseline refresh) or SQL psql loads (--output-format psql). A dump in any other format stays out of scope. verify (baseline-anchored, live-source and recover-input) is supported.


Divisions and avg() on the PostgreSQL port

From 0.139.1 the copy answers a division and an avg() of numerics or whole numbers written without round(), so percentages, shares and averages no longer have to run on your PostgreSQL. The value is the same number, written with another count of decimals (by design):

Same statementPostgreSQLThe copy
A quotient from 1 to 9999often 16 decimals: 7.50000000000000007.5000000000000000
A quotient of 10000 or more12 decimals16 decimals
A quotient below 10.333333333333333333330.3333333333333333
2.00 / 220 decimals16 decimals

Where such a value filters, groups, sorts or is summed, the rows can differ when the result turns on a digit past the sixteenth decimal:

  • amount / 3 = 33333.333333333333 can match a row on one side and not on the other.
  • a / b * b = a can be true on one side and false on the other.
  • GROUP BY a / b of two quotients that differ only past the sixteenth decimal can be one group on one side and two on the other.

To get PostgreSQL's exact text, write round(a / b, k) or round(avg(x), k). Those did not change. A server that hides tables or columns, which sends nothing to your PostgreSQL, divides and averages as before. What still goes to your PostgreSQL, such as a divisor of zero, two whole numbers or a double precision: which side answers a statement.

On this page