昨天發現發布服務器S(SQL Server 2008 R2),出現大量如下錯誤
錯誤細節如下所示:
Date 10/16/2013 4:04:14 PM Log SQL Server (Current - 10/16/2013 3:44:00 PM) Source spid52 Message Replication-Replication Transaction-Log Reader Subsystem: agent xxxxx failed. The process could not execute 'sp_repldone/sp_replcounters' on ' ServerName'.
我在發布服務器S上啟用Launch Replication Monitor(復制監視器),查看一些具體情況,如下所示
Error messages: The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20011) Get help: http://help/MSSQL_REPL20011 The specified LSN {00000000:00000000:0000} for repldone log scan occurs before the current start of replication in the log {000988e1:0000577e:00b4}. (Source: MSSQLServer, Error number: 18768) Get help: http://help/18768 The process could not set the last distributed transaction. (Source: MSSQL_REPL, Error number: MSSQL_REPL22017) Get help: http://help/MSSQL_REPL22017 The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'. (Source: MSSQL_REPL, Error number: MSSQL_REPL22037) Get help: http://help/MSSQL_REPL22037
另外發現Log Reader Agent(日志讀取器代理)呈現錯誤狀態,首先嘗試通過關閉Log Reader Agent(日志讀取器代理),然后重啟Log Reader Agent(日志讀取器代理),Log Reader Agent(日志讀取器代理)依然啟動不了,重啟SQL Server Agent(SQL Server 代理),問題仍然存在,檢查msrepl_commands記錄數,當時記錄數是761490,可以排除頒發庫的 msrepl_commands 表里面的數據太多,導致清理花費太長時間的原因。
SELECT COUNT(1) FROM msrepl_commands
於是執行下面SQL:
EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1 EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 0 exec sp_replflush
SQL執行完成后,日志讀取器代理成功啟動。重啟初始化訂閱后,問題解決。
下面是MSDN關於sp_repflush 和sp_repldone的解釋:
sp_replflush 用於事務復制。
為了提高效率,項目定義存儲在緩存中。只要修改或刪除項目定義,其他復制存儲過程都可使用 sp_replflush。
只有一個客戶端連接有權訪問給定數據庫的日志讀取器。如果某個客戶端有權訪問數據庫的日志讀取器,則執行 sp_replflush 將導致該客戶端釋放其訪問權。這樣一來,其他客戶端就能使用 sp_replcmds 或 sp_replshowcmds 掃描事務日志了
sp_repldone 用於事務復制。
sp_repldone 由日志讀取器進程用來跟蹤哪些事務已分發。
使用 sp_repldone,您可以手動通知服務器事務已復制(即已發送到分發服務器)。它還允許您更改被標記為下一個等待復制的事務。您可以在已復制事務的列表中前后移動。(所有小於或等於該事務的事務都將標記為已分發。)
可以使用 sp_repltrans 或 sp_replcmds 獲得所需的參數 xactid 和 xact_seqno。
參考資料:
http://www.sqlservercentral.com/Forums/Topic105590-7-1.aspx#bm892474


