With transactional replication, the Logreader Agent invokes the sp_MSadd_replcommands27hp stored procedure to insert the log records from the publisher to the distribution database. The Distribution Agent invokes the sp_MSget_repl_commands stored procedure to select the commands that will distributes them to the subscriber.
The Logreader Agent insert the log records include xact_seqno column to the MSRepl_transactions and MSRepl_commands system table.
The Distribution Agent distributes the data from the MSRepl_commands system table to the subscriber, and insert a record (into MSdistribution_history )for every xact_seqno which transaction had been distribute to the suscriber.
detial description:
The Log Reader Agent runs either continuously or according to a schedule you establish at the time the publication is created. When executing, the Log Reader Agent first reads the publication transaction log (the same database log used for transaction tracking and recovery during regular SQL Server 2000 operations) and identifies any INSERT, UPDATE, and DELETE statements, or other modifications made to the data transactions that have been marked for replication. Next, the agent batch copies those transactions to the distribution database at the Distributor. The Log Reader Agent uses the internal stored procedure sp_replcmds to get the next set of commands marked for replication from the log. The distribution database then becomes the store-and-forward queue from which changes are sent to Subscribers. Only committed transactions are sent to the distribution database.
There is a one-to-one correspondence between transactions on the Publisher and replication transactions in the distribution database. One transaction stored in MSrepl_transactions can consist of one or more commands and each command can be broken up along a 500-Unicode-character boundary in the MSrepl_commands table. After the entire batch of transactions has been written successfully to the distribution database, it is committed. Following the commit of each batch of commands to the Distributor, the Log Reader Agent calls sp_repldone to mark where replication was last completed. Finally, the agent marks the rows in the transaction log that are ready to be truncated. Rows still waiting to be replicated are not truncated. The transaction log on the Publisher can be dumped without interfering with replication, because only transactions not marked for replication are purged.
other web link:
http://www.yesky.com/imagesnew/software/tsql/ts_sp_repl3_7ug5.htm
http://www.yesky.com/imagesnew/software/tsql/ts_sp_repl3_21df.htm
http://www.yesky.com/imagesnew/software/tsql/ts_sp_repl3_1d2r.htm
验证方法
declare @newtime nchar(100)
--get last_xact_seqno
select xact_seqno as last_xact_seqno from MSdistribution_history
where agent_id = 6 and timestamp in(select max(timestamp)from MSdistribution_history )
set @newtime = convert(nchar(100),getdate(),114)
insert into MARKET_P4116.testDenny.dbo.testTable values (@newtime,'')
select max(xact_seqno) as dist_max_xact from dbo.MSrepl_transactions
select * from MARKET_P4116.testDenny.dbo.testTable where keyfield = @newtime
select * from [MARKET_P4116/SQL2005DV3].asdf.dbo.testTable where keyfield = @newtime
本文介绍了在SQL Server中,如何通过Logreader Agent和Distribution Agent跟踪并同步事务到订阅库,特别是在使用transactional replication时。Logreader Agent从发布者日志中获取标记为复制的事务,并将它们插入到分布数据库的系统表中。Distribution Agent随后将这些更改分发到订阅者,并在MSdistribution_history表中记录每个已分发的事务序列号。

被折叠的 条评论
为什么被折叠?



