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() MSrepl_commands WITH (PAGLOCK)

    WHILE 1 = 1
BEGIN
DELETE 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 parameter
SELECT @num_commands = @num_commands + @row_count IF @row_count < 20000 -- passed the result set. We're done
BREAK
END

2,DELETE TOP() MSrepl_commands WITH (PAGLOCK)

WHILE 1 = 1
BEGIN
if @has_immediate_sync = 0
DELETE TOP(20000) MSrepl_commands WITH (PAGLOCK) from MSrepl_commands with (INDEX(ucMSrepl_commands)) where
publisher_database_id = @publisher_database_id and
xact_seqno <= @max_xact_seqno and
(type & ~@snapshot_bit) not in (@directory_type, @alt_directory_type) and
(type & ~@replpost_bit) <> @scriptexec_type
OPTION (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)) where
publisher_database_id = @publisher_database_id and
xact_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) and
not exists (select * from MSsubscriptions s with (nolock) where
s.publisher_database_id = @publisher_database_id and
s.article_id = MSrepl_commands.article_id and
s.subscriber_id < 0)
)
)
OPTION (MAXDOP 1) select @row_count = @@rowcount
-- Update output parameter
select @num_commands = @num_commands + @row_count IF @row_count < 20000 -- passed the result set. We're done
BREAK
END

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

USE distribution
GO SELECT
T.[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) C
ON 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
GO SELECT
T.[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) C
ON 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).

设置Distribution clean up 每次删除Command的数量的更多相关文章

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

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

  2. 将SD卡的音频设置为手机铃声后删除,手机铃声没有恢复到默认的问题

    1. Android7.0,将存储卡中MP3设置为铃声,删除该MP3后,settings中的铃声没有变化,来电铃声也没有变化. 原因:android7.0的新特性 google 默认如此设计,在选择铃 ...

  3. react使用map生成的元素,key的设定不对导致每次删除都删除最后一个

    假设 你的key设置为map中的索引,假设为0,1,2(原dom树),现在你用splice删除掉1,重新渲染时,还是会按map索引按顺序渲染为0,1(新dom树),由于react渲染机制是比较的key ...

  4. Python3 tkinter基础 Canvas coords 移动直线,itemconfig 设置矩形的颜色, delete 删除一条直线

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. github 或者gitlab 设置添加SSH, 避免每次提交重复输入用户名

    克隆项目二种方式: 1. 使用https url克隆,   复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...

  6. 设置php的环境变量 php: command not found

    执行远程服务器上的某个脚本,却报错,提示php:command not found 找不到php命令 which php  结果是/usr/local/php/bin/php echo $PATH 结 ...

  7. mysql 两张表的数据设置主外健关联删除

    image_group 主表 image 副表 alter table image add constraint fk_group_idforeign key (group_id)references ...

  8. PL/SQL如何设置当前格局确保每次打开都给关闭前一样

    打开plsql  --> windows-->save layout 即可

  9. linux下 设置php的环境变量 php: command not found

    在自己的根目录进行运行phpinfo();     查看php的根目录. 假如自己查询的目录是/www/wdlinux/apache_php-5.6.21/bin, 查询完成后,先进入linux目录查 ...

随机推荐

  1. 微信小程序火车票查询 直取12306数据

    最终效果图: 样式丑哭了,我毕竟不是前端,宗旨就是练练手,体验微信小程序的开发,以最直接的方式获取12306数据查询火车票. 目录结构: search1是出发站列表,search2是目的站列表,命名没 ...

  2. mac下配置xampp多端口

    首先下载并安装完XAMPP软件. 第一步: 打开XAMPP安装目录,找到配置文件. 如:/Applications/XAMPP/etc/httpd.conf 打开后查找 Listen 80 会看到以下 ...

  3. [RxJava^Android]项目经验分享 --- 异常方法处理

    简单介绍一下背景,最近RxJava很火,我也看来学习一下,计划在项目的独立模块中使用它.使用过程中遇到很多问题,在这里记录分享一下.可能有使用不当的地方,大家多多包涵.对于RxJava的基本概念和功能 ...

  4. js 短信验证码 计时器

    $(function(){ getMsg(); //页面加载完成之后执行 }) function getMsg(){ //注册按钮的点击事件 $("#smsBtn").on(&qu ...

  5. bootstrap之强调文本的类(带颜色)

    bootstrap之强调文本的类(带颜色) <small>本行内容是在标签内</small><br> <strong>本行内容是在标签内</str ...

  6. javaweb初学记录

    原文 链接 http://blog.csdn.net/iojust/article/details/52429805 - ---热情依旧 - 环境搭建: - jdk环境配置 jdk下载: http:/ ...

  7. jquery常见获取高度

    jquery获取文档高度和窗口高度,$(document).height().$(window).height() $(document).height():整个网页的文档高度 $(window).h ...

  8. 汉字正则表达式[\u4E00-\u9FFF]原因

    转载易天:正则表达式的汉字匹配 这里是几个主要非英文语系字符范围 2E80-33FFh:中日韩符号区.收容康熙字典部首.中日韩辅助部首.注音符号.日本假名.韩文音符,中日韩的符号.标点.带圈或带括符文 ...

  9. webform 图片验证码制作

    界面:1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.as ...

  10. [转]定位占用oracle数据库cpu过高的sql

    今天在吃饭的时候我的朋友的数据库出现了问题,cpu占用率为97%,当我看到这个问题的时候我就想到了或许是sql导致的此问题,由于忍不住吃饭,暂时没有帮他看这个问题,这是我饭后自己模拟的故障,进行的分析 ...