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

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:

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



本文转自悦光阴博客园博客,原文链接:http://www.cnblogs.com/ljhdo/p/5748922.html,如需转载请自行联系原作者
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
9月前
如何关掉Parsed mapper file日志打印
如何关掉Parsed mapper file日志打印
197 1
|
4月前
|
小程序
【小程序】报错:no such file or directory, access ‘wxfile://usr/miniprogramLog/log2‘
【小程序】报错:no such file or directory, access ‘wxfile://usr/miniprogramLog/log2‘
870 0
|
1月前
|
安全 网络安全 数据安全/隐私保护
auth required pam_tally2.so file=/var/log/tallylog onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300 什么作用?
【8月更文挑战第2天】auth required pam_tally2.so file=/var/log/tallylog onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300 什么作用?
13 1
|
23天前
|
安全 网络安全 数据安全/隐私保护
auth required pam_tally2.so file=/var/log/tallylog onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300 什么作用
【8月更文挑战第14天】auth required pam_tally2.so file=/var/log/tallylog onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300 什么作用
12 0
|
2月前
|
关系型数据库 MySQL 数据库
MySQL 启动日志报错: File /mysql-bin.index not found (Errcode: 13 - Permission denied)
MySQL 启动日志报错: File /mysql-bin.index not found (Errcode: 13 - Permission denied)
141 2
|
4月前
|
存储 关系型数据库 数据库
关系型数据库文件方式存储LOG FILE(日志文件)
【5月更文挑战第11天】关系型数据库文件方式存储LOG FILE(日志文件)
155 1
|
4月前
|
运维 应用服务中间件 网络安全
利于群晖的File Station+SFTP实现第三方人员快速获取服务器应用日志
利于群晖的File Station+SFTP实现第三方人员快速获取服务器应用日志
210 0
|
10月前
|
关系型数据库 MySQL
MySQL - File /var/log/mysql/mysql-bin.index not found (Errcode 13 - Permission denied)
MySQL - File /var/log/mysql/mysql-bin.index not found (Errcode 13 - Permission denied)
192 0
|
12月前
|
应用服务中间件 PHP nginx
PHP ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
PHP ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)
112 1
|
11月前
|
关系型数据库 MySQL 数据库
阿里云Mysql数据库物理全备文件恢复到自建数据库Mysql报错:InnoDB: Log file ./...xtrabacku
阿里云Mysql数据库物理全备文件恢复到自建数据库Mysql报错:InnoDB: Log file ./...xtrabacku
下一篇
DDNS