檢查數(shù)據(jù)庫日志,有以下報錯信息:
Error: 9002, Severity: 17, State: 4.
The transaction log for database 'SharedServices1_Search_DB' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases
查看當前日志的使用情況:
這里日志并沒有完全滿,但已占用70GB日志文件的79%,也有50多GB了,個人感覺這是不正常的。個人曾讀過《SQL Server 2012實行與管理實戰(zhàn)指南》,在日志這1塊有這么1段描寫:
由于利用程序設計問題,有些連接可能會遺留1個事務在SQL Server里面,而不是及時提交它,SQL Server是不會干預用戶的這類行動的。只要這個連接不退出,這個事務會永久存在,直到客戶端主動提交或回滾。從這個事務開啟的那個時間點開始的所有日志記錄,SQL Server都會保存(做過日志備份也沒有用)。
所以長事務的存在是最可疑的線索。
在系統(tǒng)視圖sys.databases中查看數(shù)據(jù)庫‘SharedServices1_Search_DB’的log_reuse_wait及l(fā)og_reuse_wait_desc 值:
這里可以看到log_reuse_wait_desc值為‘ACTIVE_TRANSACTION’
也就是說日志正在等待transaction的檢查點。這里進1步證明了是長事務致使了超大的事務日志是由超長事務所致使的。
關(guān)于sys.databases視圖的描寫參見(https://msdn.microsoft.com/zh-cn/library/ms178534.aspx+%20+%22%E5%AE%98%E6%96%B9%E8%AF%B4%E6%98%8E%22)
查看長事務:
currentdate
2015-04-08 14:47:42.430
可以看到果然有長事務在運行,而且已運行近90分鐘了。
查看transaction相干信息:
select session_id,transaction_id,is_user_transaction,is_local
from sys.dm_tran_session_transactions
where is_user_transaction=1
session_id transaction_id is_user_transaction is_local
1566 3452140915 1 1
根據(jù)session_id查看transaction具體內(nèi)容:
select s.text from sys.dm_exec_connections c
cross apply sys.dm_exec_sql_text(c.most_recent_sql_Handle) s
where session_id=1566
text
CREATE PROCEDURE dbo.proc_MSS_Crawl ..............................
也能夠通過transaction_id看1下這個事務目前的狀態(tài):
select transaction_begin_time,
case transaction_type
when 1 then 'Read/Write transaction'
when 2 then 'Read-Only transaction'
when 3 then 'System transaction'
when 4 then 'Distributed transaction'
end tran_Type,
case transaction_state
when 0 then 'not been comoletely initaialiaed yet'
when 1 then 'initaialiaed but ha notstarted'
when 2 then 'active'
when 3 then 'ended (read-only transaction)'
when 4 then 'commit initiated for distributed transaction'
when 5 then 'transaction prepared and waiting resolution'
when 6 then 'commited'
when 7 then 'being rolled back'
when 0 then 'been rolled back'
end transaction_state
from
sys.dm_tran_active_transactions
where transaction_ID=3452140915
transaction_begin_time tran_Type transaction_state
2015-04-08 13:13:52.040 Read/Write transaction active
肯定出來語句了,就能夠找開發(fā)人員1起看看是為何了。