码迷,mamicode.com
首页 > 数据库 > 详细

在Publisher DB中查看未被Log Reader读取的Transaction 和 Commands

时间:2016-07-30 22:27:39      阅读:485      评论:0      收藏:0      [点我收藏+]

标签:

在Publisher DB中,如果 sys.objects 的 is_published =1,或 sys.tables 的 is_published=1 或 is_replicated=1,表示该Table是Publication的Article,对这些object的更新,产生的事务会被标记为Replicated,需要被Log Reader读取到Distribution中。在同一时间,只有一个Connection拥有读取Transaction Log的权限。调用 sp_replshowcmds and sp_replcmds 能够获取读取Transaction Log的权限,调用 sp_replflush 能够使拥有权限的Connection释放权限。sp_replshowcmds 是一个diagnostic sp,用于troubleshooting,第一次调用 sp_replcmds 的 Session 会被认为是Log Reader,标记一批Transaction 正在被Log Reader Agent 读取,当被标记的Transaction都转存到distribution中之后,Log Reader 调用 sp_repldone 将Transaction标记为Distributed,该事务可以被安全删除。

一,使用 Stored Procedure 控制Transaction的读取
1,查看Transaction

Returns a result set of all the transactions in the publication database transaction log that are marked for replication but have not been marked as distributed.

sp_repltrans

sp_repltrans returns information about the publication database from which it is executed, allowing you to view transactions currently not distributed (those transactions remaining in the transaction log that have not been sent to the Distributor). The result set displays the log sequence numbers of the first and last records for each transaction. sp_repltrans is similar to sp_replcmds (Transact-SQL) but does not return the commands for the transactions.

2,使用sp查看Command,但不会读取

Returns the commands for transactions marked for replication in readable format. sp_replshowcmds can be run only when client connections (including the current connection) are not reading replicated transactions from the log.

sp_replshowcmds [ @maxtrans = ] maxtrans

sp_replshowcmds is used in transactional replication. Using sp_replshowcmds, you can view transactions that currently are not distributed (those transactions remaining in the transaction log that have not been sent to the Distributor).

Clients that run sp_replshowcmds and sp_replcmds within the same database receive error 18752. To avoid this error, the first client must disconnect or the role of the client as log reader must be released by executing sp_replflush. After all clients have disconnected from the log reader, sp_replshowcmds can be run successfully.

sp_replshowcmds is a diagnostic procedure that returns information about the publication database from which it is executed.

Number: 18752, State: 1, Procedure: , LineNumber: 0, Server: , Source: .Net SqlClient Data Provider
Message: Only one Log Reader Agent or log-related procedure (sp_repldone, sp_replcmds, and sp_replshowcmds) can connect to a database at a time. If you executed a log-related procedure, drop the connection over which the procedure was executed or execute sp_replflush over that connection before starting the Log Reader Agent or executing another log-related procedure.

3,Flushes the article cache

sp_replflush

Article definitions are stored in the cache for efficiency. sp_replflush is used by other replication stored procedures whenever an article definition is modified or dropped.

Only one client connection can have log reader access to a given database. If a client has log reader access to a database, executing sp_replflush causes the client to release its access. Other clients can then scan the transaction log using sp_replcmds or sp_replshowcmds.

Importance:You should not have to execute this procedure manually. sp_replflush should only be used for troubleshooting replication as directed by an experienced replication support professional.

4,读取Commands

Returns the commands for transactions marked for replication.

sp_replcmds [ @maxtrans = ] maxtrans

sp_replcmds is used by the log reader process in transactional replication.

Replication treats the first client that runs sp_replcmds within a given database as the log reader.

This procedure can generate commands for owner-qualified tables or not qualify the table name (the default). Adding qualified table names allows replication of data from tables owned by a specific user in one database to tables owned by the same user in another database.

Clients who attempt to run sp_replcmds within the same database receive error 18752 until the first client disconnects. After the first client disconnects, another client can run sp_replcmds, and becomes the new log reader.

A warning message number 18759 is added to both the Microsoft SQL Server error log and the Microsoft Windows application log if sp_replcmds is unable to replicate a text command because the text pointer was not retrieved in the same transaction.

5,将Transaction标记为distributed

sp_repldone is used by the log reader process to track which transactions have been distributed. Updates the record that identifies the last distributed transaction of the server.

sp_repldone [ @xactid= ] xactid 
        , [ @xact_seqno= ] xact_seqno 
    [ , [ @numtrans= ] numtrans ] 
    [ , [ @time= ] time 
    [ , [ @reset= ] reset ]
        

With sp_repldone, you can manually tell the server that a transaction has been replicated (sent to the Distributor). It also allows you to change the transaction marked as the next one awaiting replication. You can move forward or backward in the list of replicated transactions. (All transactions less than or equal to that transaction are marked as distributed.) The required parameters xactid and xact_seqno can be obtained by using sp_repltrans or sp_replcmds.
caution:If you execute sp_repldone manually, you can invalidate the order and consistency of delivered transactions. sp_repldone should only be used for troubleshooting replication as directed by an experienced replication support professional.

 

参考doc:

sp_replshowcmds (Transact-SQL)

Replication Stored Procedures (Transact-SQL)

在Publisher DB中查看未被Log Reader读取的Transaction 和 Commands

标签:

原文地址:http://www.cnblogs.com/ljhdo/p/5721668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!