Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Apply snapshot from Alternate folder to improve performance when initialize a Subscription in Transactional Replication
訂閱的初始化有兩個過程:
1.產生snapshot file,這個是snapshot agent所負責的工作。
Type of Replication |
Common Snapshot Files |
SnapshotReplication or Transactional Replication | schema (.sch);data (.bcp); constraints and indexes (.dri); constraints (.idx); triggers(.trg):for updating Subscribers only; compressed snapshot files (.cab). |
MergeReplication | schema (.sch);data (.bcp); constraints and indexes (.dri); triggers (.trg); system tabledata (.sys); conflict tables (.cft); compressed snapshot files (.cab). |
2.套用snapshot到訂閱,這個是distribution agent所負責的工作。
越是大型的發行集初始化需要更多時間約多,在第二個過程[套用snapshot到訂閱],可以使用替代路徑(也就是改用訂閱者的本機路徑)來加速套用時的速度,我們可以手動將快照目錄複製到訂閱者端的本機路徑,然後在訂閱者啟動散發代理程式(Distribution Agent)指定本機路徑來套用snapshot到訂閱,步驟如下:
1.如果已經建立好發行集與訂閱,則先將散發代理程式(Distribution Agent) Job 停止(Stop)並停用(Disable)。
(1)PUSH (distribution agent running on the distributor)如果您是預設的PUSH訂閱,就在散發者將散發代理程式(Distribution Agent) Job 停止(Stop)並停用(Disable)。
(2)PULL (distribution agent running on the subscriber)如果您是預設的PULL訂閱,就在訂閱者將散發代理程式(Distribution Agent) Job 停止(Stop)並停用(Disable)。
2.在散發者啟動快照代理程式(Snapshot Agent),產生快照檔。
快照檔會產生在散發者預設的路徑下:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\repldata\unc\發行者_發行資料庫_發行集名稱\快照的日期目錄
3.手動複製快照目錄到訂閱者。(PS.訂閱者替代路徑必要有unc目錄存在,而下一個步驟所指定的替代路徑需指定在unc目錄的上一層)
例如:我們在訂閱者建立此目錄C:\Temp\Snapshot\unc,然後再把散發者的[發行者_發行資料庫_發行集名稱]目錄複製過來(基本上我們只要裡面最新的日期目錄)。
4.指定替代路徑來套用snapshot。
(1)PUSH (distribution agent running on the distributor)如果您是預設的PUSH訂閱,就在訂閱者手動執行以下命令。
C:\Program Files\Microsoft SQL Server\90\COM>DISTRIB.exe -Subscriber [SQL2K5REPL3] -SubscriberDB [MyDB2] -Publisher [SQL2K5REPL2] -Distributor [SQL2K5REPL2] -Di
stributorSecurityMode 1 -Publication [TPub1] -PublisherDB [MyDB2] -AltSnapshotFolder C:\Temp\Snapshot
此時散發代理程式(Distribution Agent)只會執行一次就會自動停止。
(2)PULL (distribution agent running on the subscriber)如果您是預設的PULL訂閱,就在訂閱者修改Distribution Agent Job的命令 將-Continuous暫時去除,在加入-AltSnapshotFolder C:\Temp\Snapshot參數,並啟動Dribtution Agent。
此時散發代理程式(Distribution Agent) Job只會執行一次就會自動停止。
5.使用複寫監視器確認散發代理程式(Distribution Agent)套用snapshot成功。
6.正常啟動散發代理程式(Distribution Agent),來繼續同步後續的交易。
(1)如果是PUSH,請將散發者上的散發代理程式(Distribution Agent) Job啟用(Enable)並啟動(Start)即可。
(2)如果是PULL,請將訂閱者上的散發代理程式(Distribution Agent) Job修改命令 將-AltSnapshotFolder C:\Temp\Snapshot 去除,再將-Continuous加回來,然後再啟動散發代理程式(Distribution Agent) Job。
[reference]
Initialize a Subscription with a Snapshot
https://msdn.microsoft.com/en-us/library/ms151795.aspx
Tips to improve performance when applying Snapshot in Transactional Replication
https://blogs.msdn.com/b/repltalk/archive/2010/03/07/tips-to-improve-performance-when-applying-snapshot-in-transactional-replication.aspx