Add and run a server
Add a PostgreSQL server from a terminal or the web interface, change, stop or remove it, and the disk and memory its copy needs.
Once your PostgreSQL is prepared, you add it to DBTrail as a server. DBTrail checks it, starts recording its changes, and makes the first copy of its tables.
Copy and paste
Add the server
the DBTrail machine, in the DBTrail folderecho "$DBTRAIL_PW" | ./dbtrail server add --flavor postgres \
-h "$PGHOST" -u dbtrail --password-stdin \
-d "$PGDATABASE" --publication bintrail_pub \
--name "$PGDATABASE" --capture-accountIt reads $PGHOST, $PGDATABASE and $DBTRAIL_PW from
Prepare, step 1. In a new terminal, type the
values instead, and let it ask for the password with -p:
./dbtrail server add --flavor postgres -h db.example.com -u dbtrail -p -d shop --publication bintrail_pubDBTrail saves nothing until every check passes, and prints the fix for each
one that fails. At the end it prints the psql line for the PostgreSQL port,
and the port's password when this is the first server.
PostgreSQL runs on this same machine? Use -h host.docker.internal.
Make the first copy and keep it current
the DBTrail machine./dbtrail snapshot run shop
./dbtrail snapshot schedule shop --every 1hThe first line reads every table once and waits until the copy is ready. The
second keeps the copy current from the recorded changes, without reading
your tables again. ./dbtrail snapshot status shop says how the last read
ended.
Check it
the DBTrail machine./dbtrail server listIt lists each server and whether its changes are being recorded.
Prefer a browser? Add it from the web interface.
Change, stop or remove a server
./dbtrail server edit shop -p # a new password for DBTrail's login
./dbtrail server edit shop -h db2.example.com # the database moved
./dbtrail server stop shop # stop recording; it stays on the list
./dbtrail server start shop # start again, after the checks pass
./dbtrail server remove shop # asks first; --yes does not ask-
Changing the address, user or password stops recording, saves, runs the checks against the new login and starts again. If the checks fail, the change stays saved and recording stays stopped, with the fix printed.
-
While a server is stopped, its replication slot keeps WAL on your PostgreSQL (why it matters).
-
Removing a server does not delete what DBTrail already recorded and copied, and does not touch your PostgreSQL. Its replication slot stays there and keeps holding WAL, which can fill the disk. Drop it yourself: first check that it exists, is not active (
f) and is not another tool's. Its name isbintrail_and the database name, unless you gave--slot.psql -c "SELECT slot_name, database, active FROM pg_replication_slots" psql -c "SELECT pg_drop_replication_slot('bintrail_shop')"Run the second line connected to the slot's database (its
databasecolumn). -
The port commands: with PostgreSQL servers,
dbtrail port onanddbtrail port statusprint thepsqlline for the PostgreSQL port (5433).dbtrail port routinganddbtrail port max-behindsay why they do not apply.
In detail
Add it from the web interface
With DBTrail installed, and no server of another database family on it (one family per installation):
- + Add server → Open the full form (the link at the foot of the Connect screen) → Source type: PostgreSQL.
- Fill in host, port, user, password, Database, Replication slot and Publication. Schemas is optional.
- Save. DBTrail runs the same checks and shows each failure with its fix. Then capture starts.
Leave ticked the box Let the PostgreSQL port send to this PostgreSQL, read-only and as the source user above, a SELECT the copy does not answer: without it, or a forwarding user of its own, the PostgreSQL port does not serve the server (Let the port ask your PostgreSQL). A separate forwarding user is under Advanced: use a separate forwarding user in the same form.
The source type cannot be changed once saved: delete the server and add it again.
The question server add asks
Once the server is added, server add asks: when the copy does not answer a
SELECT on the copy's tables, may the PostgreSQL port send it to your
PostgreSQL, read-only, as the login DBTrail already uses? Enter is yes.
--capture-accountsays yes,--no-capture-accountsays no, with no question. In an option file:capture-account = yesunder[dbtrail-forward].- Without a terminal nothing is asked and the answer is no: a script, or
the Docker
dbtrailcommand when it reads an option file on standard input. - Without forwarding, the PostgreSQL port does not serve the server: its clients get an error at login that says how to fix it. Capture keeps running.
- Later:
dbtrail server forward-user shop --capture-account, or--no-capture-accountto take it back. - A forwarding user of its own, for a port that should read more than the
copy's tables:
--forward-user, ordbtrail server forward-user shop -u app_ro -p.--no-forwardforwards nothing and asks nothing.
dbtrail server edit changes the name, address, login, schemas or S3 of a
server, but not its database, publication or --flavor.
dbtrail <command> --help lists every option.
A login that cannot read a table
Recording changes needs no SELECT. The first copy does: it reads every table
of the publication as DBTrail's login.
- Adding the server warns, and names each table the login cannot read
with the
GRANTto run. The server is still added and its changes are recorded. DBTrail grants nothing by itself. - The copy is refused with the same statements, before anything is created, until the permission is there. That also covers a table added to the publication later, and a permission taken away since.
The first copy waits for the replication slot
The first copy starts where the replication slot starts, so no change falls
between them. PostgreSQL creates the slot only after the write transactions
open at that moment have ended. Until then the server shows CREATING SLOT,
with the oldest open transaction and how long it has been open
(pg_stat_activity shows it too). Capture starts by itself once it ends. A
copy asked for meanwhile waits up to 5 minutes, then stops without reading
anything: run it again.
A table or schema whose name cannot be a file name (one with / or \, for
example) is left out of the copy, and named. The other tables are copied.
Disk for the copy
Each table is copied, compressed, into the server's Local folder. Before a full read starts, DBTrail compares the size of your tables with the free space there:
| Free in the Local folder | What happens |
|---|---|
| Less than 1 GiB | Refused, before anything is read |
| Less than 1.3× the tables' size | It runs, with a warning that it may fill the disk |
| Cannot be read | It runs, and says the check did not run |
The copy is usually much smaller than the tables: about a fifth for ordinary
order rows. Random text is closer to their size, and random bytea can be a
little bigger.
- Tables the check cannot judge (another table access method, tables with
INHERITSchildren or a TimescaleDB hypertable, a foreign table among the partitions) are named, and the note says the check cannot tell whether the copy fits. - More room: free space in the folder, or give the server a Local folder on a bigger disk (Where each server's snapshots live).
bintrail-pg baselineandbintrail-pg doctordo not run this check.
Memory for the copy
Give DBTrail 16 GB when your PostgreSQL has tables of tens of millions of
rows; 8 GB is enough for medium tables. With little memory and heavy writes,
the copy can answer minutes behind your PostgreSQL. A lag limit per server
(max_behind_source_seconds, off by default) sends those statements to your
PostgreSQL when the server has forwarding on.
What the web interface shows
- Replication health on Status: WAL the slot holds, room left before it is
lost, and tables not at
REPLICA IDENTITY FULL(The Status page). - A badge when the slot is lost: what was recorded until then stays usable, and capture must start over with a full read (Changes lost for good).
- No session on each change: PostgreSQL does not send which session made it, and the Events page says so.
Managed PostgreSQL
Amazon RDS, Aurora and Google Cloud SQL as a source, with nothing installed beyond a publication and REPLICA IDENTITY FULL.
Run and maintain DBTrail
The option file, what an update of the copy writes, table deltas and the index retention, where each server's snapshots live, the Status page, and the metrics of a PostgreSQL capture.