在邏輯複製中,正如MySQL的show slave status,或者postgresql的邏輯複製pg_stat_replication的sent_lsn,來觀察複製進度的座標位點,其複製進度座標位置都存儲在複製的源(source)端。
SqlServer的事務複製則有一些不一樣,在發佈端和訂閲端分別有一個記錄複製信息的系統表,
1,在源端,有一個MSdistribution_history系統表存儲了複製相關的信息,包括複製的事務號transaction sequence number,複製延遲,複製命令個數等等一些列複製相關的信息,另外有一個時間戳字段,這裏含義不明。
2,在目標端,MSreplication_subscriptions,存儲了源端的一些信息,其中有一個transaction_timestamp字段,該字段才是真正的複製座標位點信息,也就意味着,如果訂閲節點(從節點)斷開後重連,會用這個字段作為起始位置重新開始複製。微軟官方並沒有明確説明該字段的作用,只是説Internal-use only.
如何證明上述複製座標位點存在於訂閲的目標端而不是發佈的服務端?事務分發的數據尚未被清理之前(發佈端的distribution庫中),筆者嘗試過,可以嘗試從不同的備份分別恢復訂閲庫,訂閲庫總是可以以備份時刻的位點,精確地從分發庫獲取差異數據。
源端:分發數據庫的分發歷史表MSdistribution_history
| Column name | Data type | Description |
|---|---|---|
| agent_id | int | The ID of the Distribution Agent. |
| runstatus | int | The Running status:
1 = Start. 2 = Succeed. 3 = In progress. 4 = Idle. 5 = Retry. 6 = Fail. |
| start_time | datetime | The time to begin execution of the job. |
| time | datetime | The time the message is logged. |
| duration | int | The duration, in seconds, of the message session. |
| comments | nvarchar(4000) | The message text. |
| xact_seqno | varbinary(16) | The last processed transaction sequence number. |
| current_delivery_rate | float | The average number of commands delivered per second since the last history entry. |
| current_delivery_latency | int | The latency between the command entering the distribution database and being applied to the Subscriber since the last history entry. In milliseconds. |
| delivered_transactions | int | The total number of transactions delivered in the session. |
| delivered_commands | int | The total number of commands delivered in the session. |
| average_commands | int | The average number of commands delivered in the session. |
| delivery_rate | float | The average delivered commands per second. |
| delivery_latency | int | The latency between the command entering the distribution database and being applied to the Subscriber. In milliseconds. |
| total_delivered_commands | bigint | The total number of commands delivered since the subscription was created. |
| error_id | int | The ID of the error in the MSrepl_error system table. |
| updateable_row | bit | Set to 1 if the history row can be overwritten. |
| timestamp | timestamp | The timestamp column of this table. |
目標端:訂閲端數據庫中的訂閲表MSreplication_subscriptions
| Column name | Data type | Description |
|---|---|---|
| publisher | sysname | The name of the Publisher. |
| publisher_db | sysname | The name of the Publisher database. |
| publication | sysname | The name of the publication. |
| independent_agent | bit | Indicates whether there is a stand-alone Distribution Agent for this publication. |
| subscription_type | int | The type of subscription:
0 = Push. 1 = Pull. 2 = Anonymous. |
| distribution_agent | sysname | The name of the Distribution Agent. |
| Time | smalldatetime | The time of the last update by Distribution Agent. |
| description | nvarchar(255) | The description of the subscription. |
| transaction_timestamp | varbinary(16) | Internal-use only. |
| update_mode | tinyint | The type of update. |
| agent_id | binary(16) | The ID of the agent. |
| subscription_guid | binary(16) | The global identifier for the version of the subscription on the publication. |
| subid | binary(16) | The global identifier for an anonymous subscription. |
| immediate_sync | bit | Indicates whether synchronization files are created or re-created each time the Snapshot Agent runs. |