• 由于Replication,DBCC Shrink不能收缩Log File


    使用Backup创建测试环境之后,发现testdb的Log File过大,达到400GB,由于测试环境实际上不需要这么大的Log Space,占用400GB的Disk Space实在浪费Disk Resource,于是使用DBCC Shrink收缩Log File:

    dbcc shrinkfile(testdb_log_5,10240,notruncate)
    dbcc shrinkfile(testdb_log_5,10240,truncateonly)

    命名执行完成之后,发现还有300多GB,实际Log File占用的空间的百分比十分低,0.000428%

    DBCC SQLPERF(LOGSPACE)

    由于test db的还原模式是Simple,并且没有active user,最大的可能性是db的Trasaction log被标记为Replication,使用以下函数统计,发现有大量的log未被LogReader读取。

    select count(0)
    from sys.fn_dblog(null,null) f
    where f.Description ='REPLICATE'

    在Publisher database中,使用 sp_repltrans 查看没有被LogReader标记为Distributed的Transaction。

    sp_repltrans returns a result set of all the transactions in the publication database transaction log that are marked for replication but have not been marked as distributed.

    exec sys.sp_repltrans

    Unable to execute procedure. The database is not published. Execute the procedure in a database that is published for replication.

    由于testdb是使用backup还原的测试数据库,没有在master中注册为Publisher database,必须设置 database 为publish,表示 Database can be used for other types of publications.

    exec sys.sp_replicationdboption
            @dbname = N'testdb', 
            @optname = N'publish', 
            @value = N'true' 

    注册成功之后,使用 sp_repldone,将所有的Transaction Log 标记为Distributed。

    sp_repldone updates the record that identifies the last distributed transaction of the server.

    EXEC sys.sp_repldone 
            @xactid = NULL, 
            @xact_segno = NULL, 
            @numtrans = 0,     
            @time = 0, 
            @reset = 1  

    When xactid is NULL, xact_seqno is NULL, and reset is 1, all replicated transactions in the log are marked as distributed. This is useful when there are replicated transactions in the transaction log that are no longer valid and you want to truncate the log,

    最后,使用DBCC ShrinkFile命令,Transaction Log File收缩完成。

    参考doc:

    sp_repltrans (Transact-SQL)

    sp_replicationdboption (Transact-SQL)

    sp_repldone (Transact-SQL)

  • 相关阅读:
    线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
    C#打印图片
    javascript 地址栏写法
    SQLServer获取Excel中所有Sheet
    C#多页打印实现
    clear在CSS中的妙用
    mitmproxy使用总结
    本地回路抓包问题
    博客园界面优化
    CentOS基于MySQL提供的Yum repository安装MySQL5.6
  • 原文地址:https://www.cnblogs.com/ljhdo/p/5748922.html
Copyright © 2020-2023  润新知