使用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. Simulink Memory vs Unit Delay

    Memoryブロック.Unit Delayブロック共に前回の入力値を出力しますが.動作するタイミングが異なります. ●Memoryブロック シミュレーションの各時刻(ステップ)で動作し.「1ステップ」 ...

  2. Linux添加开机启动命令

    1.vi /etc/rc.d/rc.local 添加要启动的命令 如: service php-fpm start  //这样,开机就自动启动了php扩展 2. crontab -e   //是写定时 ...

  3. test imetro

    haha hahah2 hahah3 hahah4 text int main() { cout << "helloworld" << endl; } pi ...

  4. bzoj2743离线+树状数组

    奇葩染色,对于每一个点关心的是前前个同颜色的位置,但是处理方法相同 离线比较神奇,按照右端点排序,然后每次用的是左端点,就不用建可持久化树状数组(什么鬼)了 区间修改+单点查询 果断差分以后用树状数组 ...

  5. 【BZOJ】4056: [Ctsc2015]shallot

    题意 在线.可持久化地维护一条二维平面上的折线,支持查询与任意一条直线的交点个数. 点的个数和操作个数小于\(10^5\) 分析 一条折线可以用一个序列表示,可持久化序列考虑用可持久化treap. 如 ...

  6. C#遍历DataSet中数据的几种方法总结

    //多表多行多列的情况foreach (DataTable dt in YourDataset.Tables) //遍历所有的datatable{foreach (DataRow dr in dt.R ...

  7. MongoDB和Redis-NoSQL数据库-文档型-内存型

    1NoSQL简述 CAP(Consistency,Availabiity,Partitiontolerance)理论告诉我们,一个分布式系统不可能满足一致性,可用性和分区容错性这三个需求,最多只能同时 ...

  8. 关于.9.png格式图片的制作与使用

    .9.png图片其实就是png格式图片,不过它比普通的png图片外围多了1px(像素)的边框,另外就是使用这种格式的图片可以实现背景自适应大小且不失真的效果. 制作使用步骤: 1.制作属于你自己的pn ...

  9. Win32 OpenProcess打开进程失败,返回5无权限操作

    Win32 OpenProcess打开进程失败,返回5无权限操作,相信你会碰到这样的事,在IDE中可以,单独却不可以了,其实这时就需要提权了,否则是无法打开的,OpenProcess提权至Debug即 ...

  10. php中htmlspecialchars()函数和addslashes()函数的使用和区别

    在防止被注入攻击时,常会用到两个函数:htmlspecialchars()和addslashes()函数.这两个函数都是对特殊字符进行转义. 1)addslashes()作用及使用 addslashe ...