sql server日志不能shrink或truncate
Backup log [dbxxx] with truncate_only
sql server 2008之后不支持此操作,需要改为:
BACKUP LOG dbxxx TO DISK='NUL:'
如果提示数据库没有备份,则可以先做一个差异化备份。
The log was not truncated because records at the beginning of the log are pending replication or Change Data Capture. Ensure the Log Reader Agent or capture job is running or use sp_repldone to mark transactions as distributed or captured
或:
因为其开始处的记录是挂起的复制操作或变更数据捕获。请确保日志读取器代理或捕获作业正在运行,
此时,需要告诉DB此日志可以截断:
EXEC sp_repldone @xactid = NULL, @xact_segno = NULL, @numtrans = 0, @time = 0, @reset = 1
然后再执行:BACKUP LOG dbxxx TO DISK='NUL:'
,告诉DB日志已经备份,可以shink,最后:
DBCC SHRINKFILE (dbxxxx_Log, 1);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步