Replication Job “Distribution clean up: distribution” 默认设置是,每10minutes运行一次,每次删除2000个Command。这对于有1.9亿条Commands的distribution来说,显得力不从心。需要修改 sp [distribution].[dbo].[sp_MSdelete_publisherdb_trans],重新设置每次删除的Commands 数量,我的设置是每次删除20000 command。

设置的过程比较简单,在PROCEDURE [dbo].[sp_MSdelete_publisherdb_trans]中,查找2000,替换为 20000,需要修改三个地方

1, DELETE TOP(20000) MSrepl_commands WITH (PAGLOCK)

    WHILE 1 = 1BEGINDELETE TOP(20000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands))WHERE publisher_database_id = @publisher_database_id AND xact_seqno IN (SELECT DISTINCT snap_xact_seqno FROM @snapshot_xact_seqno)OPTION (MAXDOP 1)SELECT @row_count = @@rowcount-- Update output parameterSELECT @num_commands = @num_commands + @row_countIF @row_count < 20000 -- passed the result set.  We're doneBREAKEND

2,DELETE TOP(20000) MSrepl_commands WITH (PAGLOCK)

WHILE 1 = 1BEGINif @has_immediate_sync = 0DELETE TOP(20000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands)) wherepublisher_database_id = @publisher_database_id andxact_seqno <= @max_xact_seqno and(type & ~@snapshot_bit) not in (@directory_type, @alt_directory_type) and(type & ~@replpost_bit) <> @scriptexec_typeOPTION (MAXDOP 1)else-- Use nolock hint on subscription table to avoid deadlock-- with snapshot agent.DELETE TOP(20000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands)) wherepublisher_database_id = @publisher_database_id andxact_seqno <= @max_xact_seqno and-- do not delete directory, alt directory or script exec commands. they are deleted -- above. We have to do this because we use a (nolock) hint and we have to make sure we -- don't delete dir commands when the file has not been cleaned up in the code above. It's-- ok to delete snap commands that are out of retention and perform lazy delete of dir(type & ~@snapshot_bit) not in (@directory_type, @alt_directory_type) and(type & ~@replpost_bit) <> @scriptexec_type and(-- Select the row if it is older than max retention.xact_seqno <= @max_immediate_sync_seqno or -- Select the snap cmd if it is not for immediate_sync article-- We know the command is for immediate_sync publication if-- the snapshot tran include articles that has virtual-- subscritptions. (use subscritpion table to avoid join with-- article and publication table). We skip sync tokens because -- they are never pointed to by subscriptions...((type & @snapshot_bit) <> 0 and(type & ~@snapshot_bit) not in (@syncinit, @syncdone) andnot exists (select * from MSsubscriptions s with (nolock) wheres.publisher_database_id = @publisher_database_id ands.article_id = MSrepl_commands.article_id ands.subscriber_id < 0)))OPTION (MAXDOP 1)select @row_count = @@rowcount-- Update output parameterselect @num_commands = @num_commands + @row_countIF @row_count < 20000 -- passed the result set.  We're doneBREAKEND

3,使用Script 查看Command的分布图

USE distribution
GOSELECTT.[publisher_database_id],DATEPART(mm, [entry_time]) 'month',DATEPART(dd, [entry_time]) 'day',DATEPART(hh, [entry_time]) 'hour',COUNT(C.[xact_seqno]) 'count of commands'
FROM [dbo].[MSrepl_transactions](nolock) T
INNER JOIN [dbo].[MSrepl_commands](nolock) CON T.[xact_seqno] = C.[xact_seqno]and T.publisher_database_id=c.publisher_database_id
GROUP BY    T.[publisher_database_id],DATEPART(mm, [entry_time]),DATEPART(dd, [entry_time]),DATEPART(hh, [entry_time])
ORDER BY 1, 2, 3, 4

附上本机的查询结果

引用文档《 How to resolve when Distribution Database is growing huge (+25gig)》

Yes, I know, huge database is kind of relative, but generally if you see Distribution database growing more the 25gig it means the Cleanup processes is having a hard time deleting replicated transactions.  I’ll cover the how and why on Cleanup processes later, but for now I wanted to post a technique we’ve used to purge rows from the Distribution database.  This solution involves modifying the SQL Replication stored procedures to increase the number or rows being deleted per transaction.  If you’re uncomfortable making the code change, skip down to STEP 7).

This first posting coverage a “conservative” approach.  Later I’m post steps for a more “aggressive” solution.

1) script msrepl_commands cleanup proc and save original sp code

sp_helptext  sp_MSdelete_publisherdb_trans

2) change from CREATE to ALTER

ALTER PROCEDURE sp_MSdelete_publisherdb_trans

3) change all 3 locations from 2000 to 100000 rows

DELETE TOP(2000) MSrepl_commands . . .

4) script msrepl_transaction cleanup proc and save original sp code

sp_helptext sp_MSdelete_dodelete

5) change from CREATE to ALTER

ALTER PROCEDURE sp_MSdelete_dodelete

6) change both locations from 5000 to 100000 rows

delete TOP(5000) MSrepl_transactions . . .

7) Determine oldest day containing transactions

USE distribution
GOSELECTT.[publisher_database_id],DATEPART(mm, [entry_time]) 'month',DATEPART(dd, [entry_time]) 'day',DATEPART(hh, [entry_time]) 'hour',COUNT(C.[xact_seqno]) 'count of commands'
FROM [dbo].[MSrepl_transactions](nolock) T
INNER JOIN [dbo].[MSrepl_commands](nolock) CON T.[xact_seqno] = C.[xact_seqno]
GROUP BY    T.[publisher_database_id],DATEPART(mm, [entry_time]),DATEPART(dd, [entry_time]),DATEPART(hh, [entry_time])
ORDER BY 1, 2, 3, 4

8) Execute cleanup via SSMS or a TSQL job to delete JUST oldest day.  (24 hours @ 5 days = 120), then continue to reduce the @max_distretention valued by a few hours for each run.

EXEC dbo.sp_MSdistribution_cleanup @min_distretention = 0, @max_distretention = 120

Example output: (4 hours to removed 340million rows)

Removed 3493 replicated transactions consisting of 343877158 statements in 15043 seconds (22859 rows/sec).

作者:悦光阴
出处:http://www.cnblogs.com/ljhdo/
本文版权归作者和博客园所有,欢迎转载,但未经作者同意,必须保留此段声明,且在文章页面醒目位置显示原文连接,否则保留追究法律责任的权利。

分类: Replication
本文转自悦光阴博客园博客,原文链接:http://www.cnblogs.com/ljhdo/p/5161590.html,如需转载请自行联系原作者

设置Distribution clean up 每次删除Command的数量相关推荐

  1. 多个 gradle 文件夹 \.gradle\wrapper\dists\ 设置gradle不是每次都下载

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 设置gradle不是每次都下载 \.gradle\wrapper\dists\ ==== ...

  2. eplan部件列表手动修改_EPLAN如何修改设备标示符规则,当插入元件时不显示设备标示符前的“-”号,每次删除很麻烦!...

    点击查看EPLAN如何修改设备标示符规则,当插入元件时不显示设备标示符前的"-"号,每次删除很麻烦!具体信息 答:点击"选项"-"设置"-& ...

  3. 每次调试都必须clean_如何使用“ The Clean Architecture”每次编写健壮的应用程序...

    每次调试都必须clean by Daniel Oliveira 丹尼尔·奥利维拉(Daniel Oliveira) 如何使用" The Clean Architecture"每次编 ...

  4. 报错There are test failures 就三个步骤即可解决,1.clean。2.删除test测试文件,3.install即可

    报错There are test failures There are test failures. Please refer to E:\java\mango\mangos\target\suref ...

  5. 《小米商城》--购物车单条数据删除、购物车数量修改、清空购物车、查看地址功能、添加地址

    在购物车页面,有清空购物车方法以及按钮, 在controler里写出delete方法,现获取请求参数cid,然后传入参数cid调用deleteCartByCid方法,然后跳转到购物车展示功能 然后调用 ...

  6. 计算机怎么消除用户密码,电脑开机设置了密码要怎么删除

    很多人的电脑都设置了开机密码,但每次开机都要输入也会觉得麻烦,怎么删除开机密码呢?下面由小编为大家整理了的方法步骤,希望对大家有帮助! 电脑删除开机密码的方法和步骤如下 一.如果记得自己设置的密码,进 ...

  7. Win10的两个实用技巧系列之华硕电脑设置面部识别的技巧、删除背景图片的方法

    Win10系统的华硕电脑怎么使用人脸解锁? 华硕电脑设置面部识别的技巧 Win10系统的华硕电脑怎么使用人脸解锁?华硕电脑想要添加面部识别,方便人脸解锁,下面我们就来看看华硕电脑设置面部识别的技巧 有 ...

  8. Centos6.8 Mysql 设置自动备份与定期删除备份文件 自测部署安装

    mkdir -p /bak/mysql_bak mkdir -p /bak/file_bak cd /bak #建立自动备份执行文件 vi  glpi_mysqlbak.sh #!/bin/bash ...

  9. 管理表空间和数据文件——维护表空间——设置默认表空间和删除表空间和删除数据文件盒临时文件...

    1.设置数据库默认表空间 当建立数据库时,使用default tablespace 选项可以设置数据库的默认表空间.在建立了数据库之后,使用alter database default tablesp ...

最新文章

  1. Keil错误fatal error: UTF-16 (LE) byte order mark detected
  2. hdu 5511 Minimum Cut-Cut——分类讨论思想+线段树合并
  3. 1.6 this关键字详解(3种用法)
  4. 探索startActivity流程及在Activity间是如何传递Intent的
  5. CodeForces - 1287B Hyperset(暴力水题)
  6. 利用python 对比相似度_头条、油条商标有多像?Python检测发现相似度高达98.4%
  7. 【剑指offer】面试题50:第一个只出现一次的字符(java)
  8. python post json 解析失败_python中json对象转换出错解决方法
  9. 数字校园项目-学生失联预警系统(二)-----项目部署
  10. 统计分组的原则是要体现什么_跨境选品有哪些方法,要遵循什么原则?
  11. gnuplot使用备忘
  12. 如何进行大数据可视化分析
  13. html table 充满div,HTML,使用div+css实现自适应table布局
  14. Extmail企业邮箱构建指南
  15. 一小时学会用Python Socket 开发可并发的FTP服务器
  16. python圆周率计算_python圆周率计算(带进度条)
  17. MP4转AVI转AMV教程:教你把B站视频导入你的MP3MP4随身听播放器
  18. 完全理解android事件分发机制
  19. 01费曼技巧 - 助你快速掌握软件测试知识
  20. Protected multilib versions XXX

热门文章

  1. Paxos、Raft不是一致性算法/协议?
  2. GitHub 中文文档正式发布
  3. CopyOnWriteArrayList实现原理及源码分析
  4. 把PPT做漂亮点真的有用,研究证明图表美观增加可信度,作者:还会影响论文引用和通过率...
  5. 画出漂亮的神经网络图!神经网络可视化工具集锦搜集
  6. 2W+好评,这个python数据分析课程免费开放3天!
  7. 哈工大导师禁止实验室硕士出去实习,称「实习就像和35岁渣男试婚」,你怎么看?...
  8. 活久见!谷歌开源“大杀器”,CV、NLP都能用!
  9. 手把手教你洞悉 PyTorch 模型训练过程,彻底掌握 PyTorch 项目实战!(文末重金招聘导师)...
  10. Adam 那么棒,为什么还对 SGD 念念不忘?一个框架看懂深度学习优化算法