Black Friday – Cyber Monday: 30% off dbSlice Desktop and Pro until Dec 2. See pricing →

Replicate Several Tables in One Run with the dbSlice Replicator

Replication guide · · 15 min read

Pair the tables of two databases, choose what a run may do, and replicate them in sequence from a single screen, with a result for each table.

Moving a database usually means moving many tables. Standing up a reporting database, refreshing a read model, or filling a test environment means repeating the same copy for dozens of tables: choose the source, choose the target, choose the key, run, read the result, and start again.

The Replicator tab removes that repetition. It reads the tables of two connections, builds the list from the target tables and pairs each one with its source table, by the same name or by a name rule, and runs the ones you tick, one after the other, with the same engine that the Synchronize tab uses for a single table.

This guide follows the Replicator tab: its controls, how tables are paired, the modes, the order of execution, what happens when a table fails or the run is cancelled, the key check, and how to save the work and run it from the command line. Availability can vary by license.

01 · ConnectSource and target connections; the tables of each are loaded
02 · PairThe target tables are listed and paired with the source by name rule or same name; adjust the others and the keys
03 · RunThe ticked tables, in list order, one at a time
04 · CheckPer-table result, and a key-only Record Diff check

1. Replicator or Synchronize?

Both tabs copy rows from a source table to a target table. They differ in how many tables a run covers and in how much can be tuned for each one.

SynchronizeReplicator
Tables per runOne.Every table you tick.
SourceA table, a view, or a SELECT.Tables.
WHERE filterYes.No.
Column mapping and maskingYes.No. Columns are matched by name.
ModesFive.The same five, for the whole run.
Resume of an interrupted tableBy checkpoint.No. Resume in Synchronize.
Record Diff (key check)One table.Each ticked table.

Use the Replicator for breadth, when the same rules apply to many tables. Use Synchronize for depth, when one table needs a filter, a mapping, or a mask.

2. Read the Replicator tab

The tab sits next to Synchronize. It has two connections at the top, a group of options, the list of tables, and below them the action buttons and the execution log. The progress bar and the Cancel button are in the fixed Processing status panel, under the connection tree.

dbSlice Replicator tab with the different-environments warning, the Source and Target connections, the Options group, the Tables to replicate grid with the Up, Down and Suggest order buttons, and the Run synchronization and Record Diff buttons after a run of four tables
The Replicator tab with demonstration connections and tables, after a run of four tables. The orange banner warns that the source and the target are in different environments.
ControlPurpose
Source and Target connectionThe database to read from and the database to write to. Click Connect on both; the tables of each are loaded.
ModeWhat a run may do to each target table. One choice for the whole run.
Page (rows)How many rows are read and written at a time.
Create table on target if missing (migration)Creates a target table that does not exist, translating the column types between the two engines.
Keep source IDENTITY (SQL Server)Keeps the identity values of a SQL Server source instead of letting the target generate new ones. On SQL Server, when the target has an IDENTITY column, Upsert and New rows only stop before writing anything and explain what your DBA needs to do: SQL Server only accepts the source key with the identity turned off, and dbSlice does not change your database settings. Keep source IDENTITY (Initial load and Full load) needs ALTER permission on the target table; without it, dbSlice says so instead of SQL Server's misleading 'object not found' message.
Don't count rows before starting (very large tables)Skips the initial count, which saves time on very large tables.
Tables to replicateOne row per target table: target table, target key, source table, source key and result. A checkbox selects the row.
Select all, Clear selection, Remove from listManage the ticks and the list. A counter shows how many tables are selected out of the total.
Up (▲), Down (▼) and Suggest orderMove the selected table up or down the list, or let dbSlice propose an order. The list order is the order of execution.
Run synchronization, Record DiffReplicate the ticked tables, or run the key check on them.
Cancel (Processing status panel)Stops the run.
Load and SaveKeep the configuration and reopen it later.
Execution logThe tables loaded, the result of each table, and a summary of the run. Open in window shows the log in a larger window, with Save (.txt or .rtf), Print and PDF.

3. Pair the tables

The target is the reference: dbSlice lists the tables of the target connection and fills the source table for each one, first by the name rule, then by the same name. When names differ by a prefix, use the name rule with *: source T* and target TR* pairs T000001_USER with TR000001_USER (the part matched by * is kept). Rebuild pairs reads both sides again and builds the list from scratch, keeping the checks and keys of pairs that did not change. Find filters the list by name. If the target has no tables yet, the list comes from the source.

The same-name comparison ignores letter case and the schema, so dbo.Customer on a SQL Server source pairs with public.customer on a PostgreSQL target.

Rows without a source table are the ones the rule did not match: pick the source in the grid or adjust the name rule and click Rebuild pairs.

  • Different names. Choose the target table in the row.
  • The key. Each row has a source key and a target key. They can have different names. The key must be unique, because it is what identifies a row on each side.
  • Tables with no pair. Remove them from the list, or leave them unticked.

The tables are read from the source as tables. There is no query as a source in this tab; a table that needs a filter, a join, or a mapping belongs in the Synchronize tab.

4. Choose the mode

The mode is the same for every table in the run. It is the same list as in the Synchronize tab, with the same wording.

ModeWhat it does to each target tableUse it for
Upsert — insert new and update existingInserts missing keys and updates rows that changed. Does not delete.Refreshing a copy that already exists.
New rows only (skip existing keys)Inserts only keys that are not in the target. Existing rows are not touched.Filling gaps without changing what is there.
Update existing only (UPDATE)Updates rows whose key exists. No inserts, no deletes.Correcting values on rows that arrived.
Initial load (INSERT into empty table)Inserts every row and fails if a key already exists.The first load of empty tables.
Full load (TRUNCATE + INSERT)Deletes every row in each target table and reloads it from the source.Rebuilding copies from scratch. Use with care.

Only Full load removes rows. In the other modes, a row that exists only in the target stays there.

Confirmations before writing

dbSlice asks for confirmation in the cases in which a mistake would be costly. They are the same confirmations as in the Synchronize tab.

  • Full load. The confirmation lists the tables that will be emptied, up to ten of them. How they are emptied is described in the next subsection.
  • A read-only profile as the target. Writing to a connection marked as read-only asks for confirmation.
  • Different environments. When the source and the target belong to different environments, for example production and test, the run asks before writing. An orange banner at the top of the tab warns about it as soon as the two connections are chosen, as in the figure.

Full load in the Replicator

Full load in this tab does not empty each table just before loading it. It first reads the foreign keys of the target, empties all the ticked tables, children before parents, and only then starts the load.

  • How tables are emptied. On PostgreSQL, one TRUNCATE statement names all the tables at once. On the other databases, a parent table that is referenced by a foreign key is emptied with DELETE.
  • No CASCADE. dbSlice does not use CASCADE, which would also empty tables that are not in the list.
  • It refuses before deleting anything when a table outside the list has a foreign key that points to a table in the list, when a child table comes before its parent in the list, when a target table does not exist, or when the foreign keys cannot be read.
  • The tables stay empty until the load ends. Plan a maintenance window, and do not run it against a database that applications are reading.

Identifiers after a load

When rows are copied with the identifiers they have in the source, the target must not generate those values again. After writing rows with the source ids, dbSlice advances the table's id generator to the largest id written — PostgreSQL sequences, Firebird 3+ and Oracle 12c+ identity columns — only forward, so the next insert in your system does not repeat an id. If it cannot (for example, missing permission), the rows stay written and the log tells you that your DBA needs to advance the generator. A generator driven by a trigger (Firebird 2.5 style) is not adjusted. This applies to the Synchronize tab as well.

5. Order of execution and foreign keys

The ticked tables run in the order of the list, one at a time. The list order is the order of execution: dbSlice never reorders it on its own during a run.

This matters when the target has foreign keys. A child table that runs before its parent can be refused for a parent key that has not arrived yet. Two buttons help you set the order.

  • ▲ and ▼ move the selected table up or down the list.
  • Suggest order proposes an order from the foreign keys of the target: a parent table comes before its children and, among the tables that can go next, the smallest comes first. It is a proposal; read it and adjust it with the arrows before running.

Also keep in mind:

  • With Full load, a child table that comes before its parent in the list makes the run refuse before deleting anything, as described above.
  • Check the result column after the run. A table that the database refuses is reported as failed, and can be run again after its parent.

6. Run, cancel, and read the result

Click Run synchronization. The log announces how many tables will be replicated, from which connection to which, and in which mode. Then, for each table, it shows its position in the run, the pair, and a line of result.

A finished table shows the rows read, the rows inserted, the rows upserted or updated, the total time, and the time split into reading, transforming, and writing. The same outcome appears in the Result column of the list, for example 0 inserted, 120 updated.

When a table fails

A table that fails does not stop the others. The run continues with the next ticked table, and the failure is shown in the Result column and in the log.

When the run is cancelled

Click Cancel in the Processing status panel to stop. The run stops at the point where it is, and the tables that had not started are reported as not run.

The final line of the log summarizes the run: how many tables finished, how many failed, and how many did not run. A run is complete when the last two numbers are zero.

7. The key check with Record Diff

Record Diff runs the same key-only check as the Synchronize tab, for each ticked table, and writes nothing.

  • It shows the totals of the source and of the target.
  • It lists the keys that are missing on each side, with a sample in the log.
  • The log shows a report per table: totals on each side, when each list was built, and the keys missing on each side.
  • It writes the outcome of each table in the Result column and colors the difference: equal — 1,204 rows on both sides, or missing: target 39 · source 0.
  • It can be cancelled.

Record Diff compares keys, not values. Two rows with the same key and different content are, for Record Diff, a match. To compare values, use Compare with Also compare column values in the Synchronize tab, as described in the guide on verifying write and read databases.

A practical routine is to run Record Diff before the replication, to see what is missing, and again afterwards, to confirm that the differences are gone.

8. Save, load, and run from the command line

Save writes the configuration to a file named *_replicator.json. Load reopens it.

What is keptDetail
Source and targetBy the name of the connection profile. A password is never written to the file.
OptionsMode, page size, and the three checkboxes.
The list of pairsSource table and key, target table and key, and whether the row is ticked.
Name ruleThe source and target masks (for example T* and TR*).

The same file can be run without the screen. The command-line mode has a job of type replicate that reads the file saved from the tab. A template is created with the --new option, and the job also appears in the Jobs screen. Use it when the replication repeats, for example every time a test environment is rebuilt.

9. Large tables and interrupted runs

Each table is run as a normal synchronization, with the same engine as the Synchronize tab. The Replicator does not keep a checkpoint for each table, so a table that was interrupted does not resume from where it stopped when the run is repeated in this tab.

For a very large table, replicate it in the Synchronize tab, where an interrupted run is resumed from its checkpoint, and leave it unticked in the Replicator. The option Don't count rows before starting also helps when the initial count is slow.

10. NoSQL destinations

The target of a replication can also be a NoSQL system: MongoDB, Cassandra, Elasticsearch, Couchbase, or Redis. The source is still a relational database such as SQL Server, PostgreSQL, or MySQL. The same applies to the Synchronize tab.

dbSlice Synchronize tab with a SQL Server table as the source and a MongoDB connection as the target, with the Upsert mode and the Record Diff and Compare buttons
The Synchronize tab with a SQL Server table as the source and a MongoDB connection as the target. Demonstration data.

All five modes are available for every NoSQL target: Upsert, New rows only, Initial load, Update existing only, and Full load.

TargetHow the rows are written
MongoDBThe value of the key column becomes the _id of the document, and the other columns become fields. The collection is created at the first write. Decimals are stored without loss, as Decimal128, and a Guid is stored as a UUID.
CassandraThe table must exist, or be created with Create table on target if missing, which converts the column types. The key column becomes the partition key.
ElasticsearchThe index has the name of the table, in lowercase, and the _id of each document is the key. The stored _source keeps the exact number, but the automatic mapping of Elasticsearch treats a decimal as a float.
CouchbaseThe collection is created if it does not exist, and the document id is the key. A decimal is stored as text, so that no digit is lost.
RedisEach row becomes a hash stored under table:key, with one field per column. A null value does not write a field.

Exact numbers in Elasticsearch and Couchbase

  • Elasticsearch. To add up or sort decimal values with precision, create the index beforehand, with the mapping you want. dbSlice does not change the mapping of an index that already exists.
  • Couchbase. Because decimals are stored as text, convert them in the query, for example with TONUMBER in SQL++.
  • Couchbase 7.x and Full load. A full load needs a primary index on the collection. Without it, dbSlice warns and does not delete anything.

These limits apply today.

  • NoSQL is a destination only. dbSlice does not read or export data from these systems.
  • Record Diff and Compare do not work with a NoSQL target yet. A replication into one of them cannot be checked with those buttons.
  • Only the five systems above are supported as NoSQL targets.

11. What the Replicator does not do

  • It is not continuous. A run starts when you start it, from the screen or as a job. It does not follow the log of the source database.
  • It does not filter, map, or mask per table. There is no WHERE filter, no column mapping, and no masking in this tab. Columns are matched by name.
  • It does not reorder by itself. Suggest order proposes a sequence, but the run follows the list as you leave it.
  • It does not use a query as a source. The source is a table.
  • It does not resume a table. Resuming is done in the Synchronize tab.
  • It does not delete, except in Full load, which empties every ticked table before loading. Rows deleted in the source remain in the target in the other modes.
  • It does not read NoSQL. The NoSQL systems are targets only.
  • It does not compare values. Record Diff checks keys.
  • It does not replace your rules. Constraints, triggers, and permissions of the target apply as they do to any write.

A careful first replication

  1. Connect to the source and the target, and read the number of tables loaded on each side.
  2. Untick everything, then tick two or three small tables.
  3. Check the pairs and the keys of those rows.
  4. Choose Upsert, or Initial load if the target tables are empty.
  5. Run Record Diff first and read the totals.
  6. Run the replication and read the Result column and the final summary.
  7. Run Record Diff again and confirm that the differences are gone.
  8. Tick the next group, parents before children, and repeat.
  9. Save the configuration with Save.

Scope of this guide

The controls and log lines described here were taken from the Replicator tab in dbSlice 2.3. The order of execution, the handling of a failed table and of a cancelled run, the modes and confirmations, the options that do not exist per table, the behavior of Record Diff, and the saved file and command-line job were confirmed against the application implementation.

The screenshot shows demonstration connections and tables. The behavior was tested in the development lab on PostgreSQL, MariaDB, MySQL 8.4, SQL Server, Firebird, and Oracle targets, and the copy from SQL Server and PostgreSQL into MongoDB 8.2, Cassandra 5.0, Elasticsearch 8.17, Couchbase 8.0 and 7.2, and Redis 7.4, including decimals, dates, uuids, and long text (72 of 72 laboratory cases); the lab has not covered other engines for this tab. On Oracle, reading and writing work page by page. No replication was executed to write this article, and no speed or capacity figure is claimed. Retry and transactional behavior of the engine are those of the Synchronize tab and are not described here as specific to the Replicator.

Not using dbSlice yet?
Try the free version on the Microsoft Store: it connects, browses data, compares structures and exports to CSV.

Try it free Watch the demos

Product, company and brand names mentioned in this guide belong to their respective owners and appear only to identify the systems dbSlice works with. dbSlice is an independent product, not affiliated with, sponsored or endorsed by them. Learn more.