使用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)

由于Replication,DBCC Shrink不能收缩Log File的更多相关文章

  1. SharePoint Config database Log file too big – reduce it!

    SharePoint Config database logs are one thing to keep an eye on since they do have a tendency to gro ...

  2. Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

    setup slave from backup i got error Got fatal error 1236 from master when reading data from binary l ...

  3. innodb log file与binlog的区别在哪里?

    Q: innodb log file与binlog的区别在哪里?有人说1.mysql的innodb引擎实际上是包装了inno base存储引擎.而innodb log file是由 inno base ...

  4. ORACLE等待事件: log file parallel write

    log file parallel write概念介绍 log file parallel write 事件是LGWR进程专属的等待事件,发生在LGWR将日志缓冲区(log_buffer)中的重做日志 ...

  5. MYSQL 5.7 无法启动(Could not open error log file errno 2)

    前两天电脑中毒, 病毒好像把mysql的 log.err 文件给删掉了.然后服务一直启动不了:Could not open error log file errno 2. 然后疯狂百度,搜索的结果大多 ...

  6. mariadb:InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes

    mariadb 启动中 InnoDB: Error: log file ./ib_logfile0 is of different size 0 起因:线上正在运行的系统,因为需要调整性能,变更了my ...

  7. Nginx启动报错: could not open error log file: open() &q

    启动nginx报如下错误: nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error ...

  8. Managing IIS Log File Storage

    Managing IIS Log File Storage   You can manage the amount of server disk space that Internet Informa ...

  9. bdb log file 预设长度的性能优化

    看代码随手记:log_put.c, __log_write() /* * If we're writing the first block in a log file on a filesystem ...

随机推荐

  1. ubuntu14.04+nvidia driver+cuda8+cudnn5+tensorflow0.12

    文章在简书里面编辑的,复制过来貌似不太好看,还是到简书的页面看吧: http://www.jianshu.com/p/c89b97d052b7 1.安装环境简介: 硬件: cpu:i7 6700k g ...

  2. 根据url下载图片

    如题:在我要动手写的时候才发现不搜索根本就是写不出来,究其原因还是因为基础不扎实,由于用的少已经没有能力写出了 首先需要获取url数据流,然后写进文件里即可,仅仅两步可惜我写不出来啊跟着搜来的内容写一 ...

  3. Python列表和元组

    Python是没有数组的概念,但是和数组比较相近的概念是列表和元素. 下面两个例子展示列表和元组. # coding=utf-8 # 元组 students = ('小明', '小黄', '小李', ...

  4. Angular 单元格合并

    在Angular实现表格输出的话,使用ng-repeat输出信息, 使用了: ng-repeat-start ng-repeat-end ng-hide="$first" < ...

  5. Java|今天起,别再扯订阅和回调函数

    编程史上有两个令人匪夷所思的说辞,一个是订阅,一个是回调函数. 我想应该还有很多同学为“事件的订阅”和“回调函数”所困扰,因为事情本来就不应该按这个套路来解释. 多直白,所谓的“回调函数”你完全可以线 ...

  6. touches 事件捕获不到

    在UIView上加载了一个UIScrollView(全屏),touches 事件捕获不到了 原因:UIView的touch事件被UIScrollView捕获了,无法传递下去 解决方法:写一个UIScr ...

  7. 关于textarea中换行、回车、空格的识别与处理

    需求:在textarea中输入文字,提交给后台后,后台输出在另一个页面,文字按原格式显示.   问题:如何还原输入框中的换行和空格? 兼容性:IE9以上.FF.chrome在换行处匹配/\n/     ...

  8. ECMAScript6 初步认识

    JavaScript由3部分组成,分别是:Dom,BOM和ECMAScript !核心(ECMAScript):由ECMA-262定义,提供核心语言功能:ECMAScript是属于国际标准化语言,所有 ...

  9. Linux下安装maven

    1.首先到Maven官网下载安装文件,目前最新版本为3.0.3,下载文件为apache-maven-3.0.3-bin.tar.gz,下载可以使用wget命令: 2.进入下载文件夹,找到下载的文件,运 ...

  10. 在Excel中把横行与竖列进行置换、打勾号

    在Excel中把横行与竖列进行置换:复制要置换的单元,在新的单元上右键->选择性复制,会出现对话框,选中“置换”,即可在Excel中打勾号,左手按住ALT不放,右手在小键盘也就是右边的数字键盘依 ...