从MSdistribution_history得到已经同步到订阅库的最后一个事务序列号
2009-12-11 19:04
246 查看
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
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 发布订阅报错-该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- SQL Server 事务复制分发到订阅同步慢
- SQLSERVER --- MSdistribution_history 判定复制订阅是否正常!
- [SQL Server] 使用事务发布与订阅实现数据同步
- SQL Server 事务复制分发到订阅同步慢
- SQL Server提高事务复制效率优化(三)订阅初始化优化
- Flask MVVM 开发(vue.js) - ajax如何同步更新地址栏history 以及使用浏览器返回按钮
- SqlServer2008 数据库同步的两种方式 (发布、订阅)
- SQL Server 2008 数据库同步的两种方式 (发布、订阅)
- MSSqlServer 主从同步复制原理(发布/订阅)
- SqlServer2008 数据库同步的两种方式 (发布、订阅)
- 使用Sqlserver事务发布实现数据同步
- 使用Sqlserver事务发布实现数据同步
- 动态加载js 前3个是同步 最后一个是异步 不要被文章骗了~
- 如果一个箱子里面有100个球,有两个玩家,1和2,他们都很聪明,可以随机从箱子里面拿出2或6个球,箱子是透明的并且箱子里面有多少个球他们也可以看得到 ,如果算最后一个球能被谁拿到,谁就是
- 该伙伴事务管理器已经禁止了它对远程/网络事务的支持
- 使用Sqlserver事务发布实现数据同步
- SQL Server 2008 数据库同步的两种方式 (发布、订阅)
- C#得到CPU的序列号、硬盘序列号、网卡序列号
- vector 如何得到最后一个元素