Method of splitting large transactions into small transaction distribution in SQL Server replication _mssql

Source: Internet
Author: User

In SQL Server replication, when 1 large transactions are performed in the publishing database, such as a one-time operation of 100,000 or more million of data. When the operational data is completed at the publication database, the Log Reader Agent scans the transaction log and passes it to the distribution database at once. If the last transaction is not delivered and multiple transactions are performed consecutively, the Log Reader Agent passes multiple transactions in the scan log to the distribution database at the same time, by default, the maximum 500 transactions are scanned. If you perform millions or tens of thousands of data, it will be blocked for a long time.

The Log Reader Agent can be configured to divide large transactions into multiple small transactions for delivery to the distribution database, and distribution queues are distributed to the subscription database according to small transactions, so that the data is synchronized quickly!

Before I changed the agent parameters, I performed 1 times to insert 300,000 of the data into the publishing table. When the insertion is complete, the monitor publishes the following records to the distribution:

As you can see, the commands for these 1 transactions have to be delivered one at a time, and the distribution is time-consuming, and this wait too long to affect the real-time nature of the transaction.
If there are other transactions, the default 500 (reference parameter:-readbatchsize) will also be passed together, taking longer.

Now change the parameters, scan to about 1000 of the command on the instant distribution, you need to set the following parameters:
-maxcmdsintran number_of_commands

Note: This parameter can only be added to the Log Reader Agent, and there is no setting for this parameter in the proxy configuration file.

Restart the Log Reader Agent after adding.

Insert 300,000 of the data again! ~ To monitor View

As you can see, the commands are distributed around 1000, and the subscription database is now available, and the data is synchronized, eliminating the time for more scanning commands.
View the number of commands for each transaction in more detail, as follows:

SELECT Top A.xact_seqno,a.entry_time,count (*) as Cmds from
distribution.dbo.MSrepl_transactions A (NOLOCK) 
INNER JOIN distribution.dbo.MSrepl_commands B (NOLOCK) 
on A.xact_seqno=b.xact_seqno
GROUP by A.xact_seqno, A.entry_time ORDER by
Cmds DESC

This parameter is good, but it can also cause data consistency.

Such as:

A batch of data was updated in the publication, but the subscription query was different.

The distribution transaction encounters a conflict or deadlock, which also results in inconsistent data in this section.

Reference: Replication Log Reader Agent

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.