Microsoft SQL Server
Replicate Microsoft SQL Server from transaction log backups
Replicate SQL Server by reading transaction log backups (.trn files) from an SMB share, with supplemental logging for updates.
With this method, Artie reads changes from your transaction log backup (.trn) files as they land in a shared folder, instead of from the live database. To build those changes, Artie queries the database only for table metadata, off-row values, and updates on tables without supplemental logging. Backfills still read the tables from the database.
Latency is at least your log backup interval, plus up to 5 minutes, because Artie checks the folder every 5 minutes.
Prerequisites
- SQL Server 2019 or later
- Database recovery model set to
FULLorBULK_LOGGED - Log backups taken on a schedule to one folder on an SMB share, such as Amazon FSx for Windows File Server. See Backup folder and file names.
- Network access from Artie to the share on port 445
- An SMB user that can read the folder. Artie signs in with NTLM and requires SMB message signing.
- A primary key on each replicated table
- Supplemental logging on each replicated table
- A service account with
SELECTon the database, for table metadata and off-row values
Set up transaction log backups
Configure log backups
Write every log backup for the database to one folder. File names must end in
_YYYYMMDD_HHMMSS.trn, with a lowercase.trnextension. For example, Ola Hallengren’s maintenance solution writes names in this format. See the settings to use with it.SQLEXECUTE dbo.DatabaseBackup @Databases = 'ANALYTICS', @Directory = '\\fs-0123456789abcdef0.corp.example.com\share\sqlbackups', @BackupType = 'LOG', @DirectoryStructure = NULL, @TokenTimezone = 'UTC', @Compress = 'Y';Use backup compression only with the
MS_XPRESS(default) orZSTDalgorithm.Create a service account
Run this in the database as a database admin. It creates the login Artie connects with and grants it
SELECTon the database.SQLUSE [ANALYTICS]; CREATE LOGIN artie_transfer WITH PASSWORD = 'PASSWORD'; CREATE USER artie_transfer FOR LOGIN artie_transfer; ALTER LOGIN artie_transfer ENABLE; GRANT SELECT on DATABASE::[ANALYTICS] to artie_transfer; GOReplace
PASSWORDwith a password for the login.If a table’s clustered index is non-unique, or isn’t on the table’s leading columns, also grant
SELECTonsys.system_internals_partition_columns. Without it, Artie can’t decode that table’s rows.Enable supplemental logging
Follow Supplemental logging for each replicated table.
Add the SMB share in Artie
In Settings > Connectors, select New connector. Choose the environment your pipeline uses, then set Connector type to SMB share.
- UNC path: the folder your log backups go to, the same path as in
BACKUP LOG ... TO DISK. For example,\\fs-0123456789abcdef0.corp.example.com\share\sqlbackups. - Username and Password: a user that can read the folder, as
DOMAIN\useroruser@domain. - PrivateLink connection (optional): pick one if the share is only reachable privately. It must forward port 445. This field appears only when PrivateLink is available to your account.
Select Test connection. The button reads Able to connect when the check passes. Then select Save.
- UNC path: the folder your log backups go to, the same path as in
Select the replication method
When you create the pipeline, go to the Connect and verify step in the Source section and enter the database connection. Under Replication method, select Transaction log backups.
Under Where are the transaction log backups stored?, choose the share in the SMB share list. The list shows only shares in the pipeline’s environment, and on its data plane if the share has one.
If setup shows a Prepare source step, its script is for capture instances. Run its service account step, then follow Supplemental logging in place of its CDC steps, because that section also drops the CDC capture job.
To switch an existing pipeline, open the Source: Microsoft SQL Server tab on the Edit pipeline page. Replication method is locked while the pipeline is running.
Verify the connection
On the Connect and verify step, select Verify source. The check includes the SMB share, and the step shows Source verified when it passes.
Supplemental logging
By default, SQL Server logs only the bytes an UPDATE changed. For those tables, Artie looks the row up in the database when it reads the backup. The message then carries the row as it is at that point, not as of the update. An update to a row deleted since is lost.
An update that writes only off-row TEXT, NTEXT or IMAGE values is lost too, because SQL Server doesn’t log the row for it. With the table option large value types out of row on, the same applies to VARCHAR(MAX), NVARCHAR(MAX), VARBINARY(MAX), XML, GEOGRAPHY and GEOMETRY values.
With supplemental logging, SQL Server logs the whole row for every update, and Artie reads updates straight from the backup, apart from off-row values. Enable it on each table in one of two ways:
Run this in the database. It enables change data capture (CDC) on each table, then drops the capture job.
USE [ANALYTICS];
GO
EXEC sys.sp_cdc_enable_db;
GO
-- For each table you want to replicate:
EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'orders', @role_name = NULL;
GO
-- Artie does not read the cdc change tables, so stop SQL Server from filling them.
EXEC sys.sp_cdc_drop_job @job_type = N'capture';
GOOn Amazon RDS, enable CDC on the database with EXEC msdb.dbo.rds_cdc_enable_db 'ANALYTICS'; instead of sys.sp_cdc_enable_db.
Use this if CDC isn’t an option. It requires a distributor and isn’t available on Amazon RDS.
-- Once per server, if no distributor is configured:
USE master;
GO
EXEC sp_adddistributor @distributor = @@SERVERNAME, @password = N'';
EXEC sp_adddistributiondb @database = N'distribution';
EXEC sp_adddistpublisher @publisher = @@SERVERNAME, @distribution_db = N'distribution';
EXEC sp_replicationdboption @dbname = N'ANALYTICS', @optname = N'publish', @value = N'true';
GO
USE [ANALYTICS];
GO
-- @retention = 0: the subscription never expires.
EXEC sp_addpublication @publication = N'artie', @status = N'active', @repl_freq = N'continuous',
@retention = 0, @allow_pull = N'true';
-- For each table you want to replicate:
EXEC sp_addarticle @publication = N'artie', @article = N'orders', @source_owner = N'dbo', @source_object = N'orders', @type = N'logbased';
-- SQL Server only logs whole rows once the publication has a subscription.
EXEC sp_addsubscription @publication = N'artie', @subscriber = @@SERVERNAME, @destination_db = N'ANALYTICS_SUBSCRIBER',
@subscription_type = N'pull', @sync_type = N'replication support only', @article = N'all';
GO-
Use a pull subscription. For a push subscription, SQL Server creates and starts a Distribution Agent job, which tries to deliver every change to the subscriber database. No agent is created for a pull subscription, and nothing is written to the subscriber database.
-
Keep
@retention = 0. With the default of 336 hours, SQL Server drops a subscription that never synchronizes after 14 days, and the tables stop logging whole rows. The distributor can still mark the subscription inactive after its maximum distribution retention, which is 72 hours by default. The tables keep logging whole rows. The subscription never receives data, so it doesn’t need reinitializing. -
@subscribercan be another server. Replace@@SERVERNAMEwith the name that server’s own@@SERVERNAMEreturns, including the instance name, not an alias or IP address. SQL Server never connects to the subscriber, so no procedures, triggers or jobs are created there. -
@destination_dbcan be any database exceptmaster, including one that doesn’t exist. Pick a name nothing else uses. -
Adding a table later? A subscription with
@article = N'all'doesn’t cover articles added after it. Aftersp_addarticle, runsp_addsubscriptionagain with the same arguments and@articleset to the new article’s name. -
No agents need to run.
sp_addpublicationcreates and starts a Log Reader Agent if the database doesn’t have one yet. If nothing else uses it, stop and disable its job, then follow Let the log truncate. -
Set up with a push subscription before? Switch it to pull. Add the pull subscription before dropping the push one, so the tables never stop logging whole rows. The pull subscription needs a different
@destination_dbfrom the push one: if they match, adding it does nothing, and dropping the push subscription leaves none.SQLUSE [ANALYTICS]; GO EXEC sp_changepublication @publication = N'artie', @property = N'retention', @value = N'0'; EXEC sp_changepublication @publication = N'artie', @property = N'allow_pull', @value = N'true'; EXEC sp_addsubscription @publication = N'artie', @subscriber = @@SERVERNAME, @destination_db = N'ANALYTICS_ARTIE', @subscription_type = N'pull', @sync_type = N'replication support only', @article = N'all'; GORun the subscription check and confirm each table has a row for
ANALYTICS_ARTIEwithstatus2. Then drop the push subscription, which also removes its Distribution Agent job:SQLEXEC sp_dropsubscription @publication = N'artie', @subscriber = @@SERVERNAME, @destination_db = N'ANALYTICS_SUBSCRIBER', @article = N'all';
Check supplemental logging
Run this query in the database. is_replicated is 1 for each table with supplemental logging.
SELECT s.name AS schema_name, t.name AS table_name, t.is_replicated
FROM sys.tables t
JOIN sys.schemas s ON t.schema_id = s.schema_id;For a publication, also check that each table has a subscription, with status 2. Distribution retention marking the subscription inactive doesn’t change this status. CDC also sets is_replicated to 1, so run this check before you disable CDC on a table that’s in a publication.
SELECT OBJECT_SCHEMA_NAME(a.objid) AS schema_name, OBJECT_NAME(a.objid) AS table_name, s.dest_db, s.status
FROM syssubscriptions s
JOIN sysarticles a ON a.artid = s.artid
JOIN syspublications p ON p.pubid = a.pubid
WHERE p.name = N'artie';When the pipeline starts, Artie logs a warning that names each configured table without supplemental logging.
Let the log truncate
Both options mark every transaction on these tables for replication. SQL Server keeps each one in the log until something marks it as distributed. Without the CDC capture job or a Log Reader Agent, log_reuse_wait_desc in sys.databases stays at REPLICATION. The log then keeps growing, even with regular log backups.
Artie reads your log backups, so marking everything as distributed on a schedule is safe. Each log backup still contains every change. Schedule this with SQL Server Agent:
USE msdb;
GO
EXEC sp_add_job @job_name = N'artie_mark_distributed';
EXEC sp_add_jobstep @job_name = N'artie_mark_distributed', @step_name = N'sp_repldone', @database_name = N'ANALYTICS',
@command = N'EXEC sp_repldone @xactid = NULL, @xact_seqno = NULL, @numtrans = 0, @time = 0, @reset = 1;';
EXEC sp_add_jobschedule @job_name = N'artie_mark_distributed', @name = N'every 15 minutes',
@freq_type = 4, @freq_interval = 1, @freq_subday_type = 4, @freq_subday_interval = 15;
EXEC sp_add_jobserver @job_name = N'artie_mark_distributed';
GOEvery 5 minutes, Artie checks whether the log is waiting on REPLICATION. It logs a warning once a database has been waiting for an hour or more.
Backup folder and file names
Artie lists one folder, without subfolders, and reads files whose names end in _YYYYMMDD_HHMMSS.trn. The match is case-sensitive, so Artie ignores a file that ends in .TRN. Artie reads files in file name order and skips any file whose name sorts before the last file it read.
- Use one folder per database, and one naming prefix. If backups land in subfolders, or different servers write different prefixes, Artie can skip files.
- Keep every log backup in the folder until Artie has read it. Artie doesn’t check that each backup starts where the previous one ended.
Protect the folder from cleanup jobs that delete files before Artie reads them.
Artie detects one case. If a transaction was still open when Artie last saved its position, Artie needs the file where that transaction began. If that file is gone, the pipeline stops with this error:
<file> is gone from the archive location, but transactions that were open or not all published at the offset began in itArtie treats a file as complete once the writer has closed it and its size is above zero. For the last file in name order, the size must also stay the same for two 3-second checks in a row.
For availability groups, see Log backups in an availability group.
Ola Hallengren’s maintenance solution
Artie is tested with Ola Hallengren’s DatabaseBackup, version 2026-11-29, in these layouts:
| Layout | DatabaseBackup setting | Folder to set as the UNC path |
|---|---|---|
| One folder | @DirectoryStructure = NULL | The @Directory folder |
| Default directory structure, outside an availability group | @DirectoryStructure left at its default | The database’s log folder, @Directory\SERVER\DATABASE\LOG |
| Default directory structure, in an availability group | @AvailabilityGroupDirectoryStructure and @AvailabilityGroupFileName left at their defaults | The database’s log folder, @Directory\CLUSTER$AG\DATABASE\LOG |
SERVER is the server name, followed by $ and the instance name on a named instance. CLUSTER is the Windows Server failover cluster name, and AG is the availability group name. DATABASE is the database name.
DatabaseBackup rejects @CleanupTime when the directory structure has no {DatabaseName} token. This happens with @DirectoryStructure = NULL, or @AvailabilityGroupDirectoryStructure = NULL on a server with availability groups enabled. The call fails with this error:
The value for the parameter @CleanupTime is not supported. Cleanup is not supported if the token {DatabaseName} is not part of the directory structure. See https://ola.hallengren.com/sql-server-backup.html#CleanupTime.When DatabaseBackup rejects @CleanupTime, delete old log backups with your own scheduled job, such as one that deletes .trn files older than a set number of days. Keep each file longer than a pipeline can pause or fall behind.
These DatabaseBackup settings break replication:
| Setting | Effect |
|---|---|
@NumberOfFiles above 1 | Splits each log backup into files ending in _1.trn, _2.trn, which Artie can’t read. Artie reads the backups before it, then the pipeline stops with an error that names its first file. |
@TokenTimezone = 'LOCAL' (the default) on a server that observes daylight saving time | File names from the repeated hour sort out of order, and Artie skips files that sort before the last one it read. Set @TokenTimezone = 'UTC'. |
@DirectoryStructure = NULL with more than one database in @Databases | Writes every database’s log backups to one folder. Once Artie reads a file of a database that sorts later, it skips the other databases’ files. Use the default directory structure, or one @Directory per database. |
@CleanupTime shorter than a pipeline can pause or fall behind | Deletes log backups before Artie reads them. |
Date or time tokens in @DirectoryStructure | Writes log backups to subfolders, which Artie doesn’t read. |
@BackupSoftware | Writes another product’s backup format. Artie reads only SQL Server’s own backup format. |
@Encrypt = 'Y', @CompressionAlgorithm = 'QAT_DEFLATE' or @URL | Not supported. See Limitations. |
To recover from a split log backup, set @NumberOfFiles = 1 and move the backup’s files out of the folder. If the pipeline started before the backup was taken, its changes aren’t replicated: contact Artie to move the pipeline past it, then backfill the affected tables.
Set @TokenTimezone = 'UTC' before the pipeline starts. On a running pipeline whose server is ahead of UTC, the first UTC file name sorts before the last local one, and Artie skips the backups in between. Switch once UTC time has passed the time in the last local file name, or backfill the tables afterwards.
How Artie reads log backups
- Every 5 minutes, Artie looks for new backup files in the folder.
- Artie parses each file’s backup container and log records, and builds row changes from the log records of the configured tables.
- Artie publishes only committed transactions, in commit order. It drops rolled-back transactions.
- A transaction that spans several log backups is held until it ends. Once its changes pass 4 MB, Artie writes them to a spool directory on disk.
- Artie saves its position (the last file and the commit LSN) only after changes are written to its Kafka buffer.
- After a restart, Artie rereads from the first file with a still-open transaction and skips changes it has already published.
- If the connection to the SMB share drops, Artie tries to reconnect for up to 2 minutes, then reads again from its saved position.
Open transactions over the spool limit
If open transactions need more than 10 GiB of spool, the pipeline stops with this error:
transactions open across log backups need more than trnCdcSettings.spoolMaxBytesEnd the transaction, or contact Artie to raise the limit.
Changes Artie can’t publish exactly
SQL Server doesn’t publish its log backup format. Artie checks each change against the table’s layout and stops instead of guessing. The pipeline stops with this error:
halted at a change that cannot be published exactly: <kind> at LSN <lsn>, table <database.schema.table>Nothing from that change on is published until it’s resolved. Contact Artie with the error. Resolving it usually means a backfill of the named table.
<kind> is one of these values:
| Kind | The change Artie stopped on |
|---|---|
update_without_row_image | An update logged without its whole row, on a table with supplemental logging |
update_row_layout_mismatch | An update whose row doesn’t match the table’s columns |
update_undecodable | An update whose row doesn’t decode with the table’s layout |
update_off_row_value_changed | An update that changes an off-row value Artie can’t read from the database, such as VARBINARY(MAX) or JSON |
update_off_row_key | An update of a row whose primary key column is stored off-row |
update_unstored_computed_column | An update on a table with a replicated computed column that isn’t persisted |
rolled_back_update_without_row_image | A rolled-back update whose original row isn’t in the log |
rolled_back_update_mismatch | A rolled-back update that doesn’t restore the whole row its update logged |
rolled_back_update_key_unknown | A rolled-back update where Artie can’t tell whether the primary key changed back |
rolled_back_change_not_kept | A rolled-back insert or update in a transaction too large for Artie to keep its changes, more than about a million rows or 64 MiB of inserted rows |
heap_forward_unverified | A heap row moved to another page, and Artie can’t confirm the move changed no values |
delete_insert_across_backups | A delete or insert that may be half of a row move split across log backups |
delete_insert_unprovable | A delete and insert of one row that Artie can’t prove is a single update |
transaction_aborted_without_undo | An aborted transaction that didn’t undo its changes |
A rolled_back_change_not_kept error also names the transaction. Each table with such a rolled-back change stops on its own, before any of that transaction’s changes to the table are replicated; the transaction’s other tables replicate as usual. The transaction has already ended, so once a table is backfilled, Artie skips all of that transaction’s changes to it. Another table with such a change stops the pipeline again, to be backfilled too.
Off-row columns
Values stored off-row, such as large VARCHAR(MAX) values, aren’t in the log with the rest of the row.
- Inserts: Artie reads off-row values from the database. If the row has been deleted by then, they’re published empty.
- Updates that leave an off-row value unchanged: the value stays as it is in the destination.
- Updates that change an
XML,VARCHAR,NVARCHAR,GEOGRAPHY,GEOMETRYorHIERARCHYIDvalue, or change the primary key of a row whose off-row values are all of these types: Artie reads the value from the database by primary key. This includesVARCHAR(n),NVARCHAR(n)andHIERARCHYIDvalues that SQL Server moved off-row to keep the row within 8,060 bytes. The value is the row’s value when Artie reads the log backup, not its value at the time of the update. If the row was updated again in between, each of those updates is published with the latest value. If the row has been deleted by then, the destination keeps its current value until the delete arrives. - Every update of a row with a
TEXT,NTEXTorIMAGEvalue off-row: Artie reads the value from the database by primary key, the same way. The row holds the same pointer whether or not the update changed the value. This also applies toVARCHAR(MAX),NVARCHAR(MAX),VARBINARY(MAX),XML,GEOGRAPHYandGEOMETRYvalues written while the table optionlarge value types out of rowwas on. - Updates that change any other off-row value, or change the primary key of a row with one: the pipeline stops with
update_off_row_value_changed. This coversVARBINARY(MAX),VARBINARY(n)andJSON. Backfill the table, or exclude the column. - Computed columns that aren’t persisted: an update stops the pipeline with
update_unstored_computed_column. Persist the column, or exclude it.
Limitations
- Encrypted databases and backups: TDE-encrypted databases and encrypted backups aren’t supported.
- Backup compression:
QAT_DEFLATEisn’t supported. UseMS_XPRESSorZSTD. - Backup location: only SMB shares are supported. Azure Blob Storage isn’t supported.
- Accelerated database recovery and heap tables with row versioning: updates aren’t certified. Contact Artie before using them.
TRUNCATE TABLEisn’t allowed on tables tracked by CDC or published for replication.- Latency is at least your log backup interval. Take log backups every few minutes for lower latency.
Was this page helpful?
- Need help? Message us on Slack or email [email protected].
- Want a walkthrough? Book a demo.
- LLM? Read llms.txt.