The transaction log for database 'xx' is full,Error: 9002, Severity: 17, State: 2,9002severity

來源:互聯網
上載者:User

The transaction log for database 'xx' is full,Error: 9002, Severity: 17, State: 2,9002severity

檢查資料庫日誌,有如下報錯資訊:

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實施與管理實戰指南》,在日誌這一塊有這麼一段描述:

由於應用程式設計問題,有些串連可能會遺留一個事務在SQL Server裡面,而不是及時提交它,SQL Server是不會幹預使用者的這種行為的。只要這個串連不退出,這個事務會永遠存在,直到用戶端主動提交或者復原。從這個事務開啟的那個時間點開始的所有日誌記錄,SQL Server都會保留(做過記錄備份也沒有用)。

所以長事務的存在是最可疑的線索。
在系統檢視表sys.databases中查看資料庫‘SharedServices1_Search_DB’的log_reuse_wait及log_reuse_wait_desc 值:

這裡可以看到log_reuse_wait_desc值為‘ACTIVE_TRANSACTION’
也就是說日誌正在等待transaction的檢查點。這裡進一步證明了是長事務導致了超大的交易記錄是由超長事務所導致的。
關於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)

查看長事務:

currentdate2015-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=1session_id  transaction_id  is_user_transaction is_local1566         3452140915             1              1

根據session_id查看transaction具體內容:

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=1566textCREATE PROCEDURE dbo.proc_MSS_Crawl ..............................

也可以通過transaction_id看一下這個事務目前的狀態:

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_state2015-04-08 13:13:52.040 Read/Write transaction  active

確定出來語句了,就可以找開發人員一起看看是為什麼了。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.