设置Distribution clean up 每次删除Command的数量

简介:

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 = 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(20000) 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).

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






本文转自悦光阴博客园博客,原文链接:http://www.cnblogs.com/ljhdo/p/5161590.html,如需转载请自行联系原作者
目录
相关文章
|
Shell 数据安全/隐私保护
执行jobs命令查看不到任务的原因终于找到了
背景 执行nohup command &后,断开终端,执行jobs命令查看不到任务的原因,终于找到了。 首先执行完如下步骤: 1.nohup scp user@server:path/file localpath 2.输入密码 3.按Ctrl+Z挂起当前进程 4.使用命令bg让挂起的进程继续运行
|
6月前
|
Docker 容器
dockers --cap-add 哪些值可以设置
`--cap-add` 参数可以用于向 Docker 容器添加不同的权限。除了 `NET_ADMIN`,还有一些其他常用的权限值,包括: 1. `SYS_ADMIN`:添加系统管理员权限,允许容器内的进程执行系统级别的管理操作,如挂载文件系统、设置时间、修改主机名等。 2. `SYS_PTRACE`:添加系统追踪权限,允许容器内的进程使用 `ptrace` 系统调用,用于调试和监视其他进程。 3. `SYS_CHROOT`:添加切换根目录权限,允许容器内的进程使用 `chroot` 系统调用,在指定的目录下创建一个新的根文件系统环境。 4. `SYS_MODULE`:添加模块加载/卸载
290 1
|
移动开发 测试技术
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
89 0
pytest学习和使用24-如何清空allure报告历史记录?我每次都手动删除,有点Low了~
|
Ubuntu JavaScript
ubuntu 文件监视数量 Error: ENOSPC: System limit for number of file watchers reached, watch‘所在文件路径‘
vue 运行执行 npm run dev | * Error: ENOSPC: System limit for number of file watchers reached, watch’所在文件路径’ 最简单的命令 沾走就能用
131 0
ubuntu 文件监视数量 Error: ENOSPC: System limit for number of file watchers reached, watch‘所在文件路径‘
|
数据库管理
find 删除命令rm还是delete更快
find 删除命令rm还是delete更快
365 0
|
前端开发
Cypress系列(21)- 可操作类型的命令 之 check()、uncheck()
Cypress系列(21)- 可操作类型的命令 之 check()、uncheck()
277 0
Cypress系列(21)- 可操作类型的命令 之 check()、uncheck()
|
JavaScript
Cypress系列(20)- 可操作类型的命令 之 clear()
Cypress系列(20)- 可操作类型的命令 之 clear()
177 0
Cypress系列(20)- 可操作类型的命令 之 clear()
svn提交更新代码提示Please execute the 'Cleanup' command 的解决办法
svn提交更新代码提示Please execute the 'Cleanup' command 的解决办法
|
SQL Oracle 关系型数据库
DROP_SNAPSHOT_RANGE过程不能清理表RM$_SNAPSHOT_DETAILS
今天在测试、验证DROP_SNAPSHOT_RANGE不能彻底快照的过程中遇到了DROP_SNAPSHOT_RANGE无法清理WRM$_SNAPSHOT_DETAILS表中数据的情况,测试服务器版本为10.2.0.4.0,AWR的快照是1小时采集一次数据,快照保留14天,也就是二周。
1099 0