sql server日誌不能shrink或truncate

margiex發表於2014-05-28
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);

相關文章