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

检查数据库日志,有如下报错信息:

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)

查看长事务:

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

根据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=1566
text
CREATE 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_state
2015-04-08 13:13:52.040 Read/Write transaction  active

确定出来语句了,就可以找开发人员一起看看是为什么了。

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

时间: 2024-08-12 10:26:28

The transaction log for database 'xx' is full,Error: 9002, Severity: 17, State: 2的相关文章

The transaction log for database 'XXX' is full due to 'ACTIVE_TRANSACTION'.

Msg 9002, Level 17, State 4, Line 4The transaction log for database 'Test' is full due to 'ACTIVE_TRANSACTION'. 本定一个测试库错误,由于此库的LOG文件被设置成不允许自动增长,而在大量输入数据的时候报出此错.此库已经使SIMPLE恢复模式. --数据库当前LOG状态 select log_reuse_wait_desc from sys.databaseswhere name = 'T

The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'

今天查看Job的History,发现Job 运行失败,错误信息是:“The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'.” 错误消息表明:数据库的事务日志文件空间耗尽,log 文件不能再存储新的transaction log. SQL Server将事务日志文件在逻辑上划分为多个VLF(Virtual Log Files),将这些VLF组成一个的环形结构,以VLF为重用单元.如果一个VLF 中存在

DB2 “The transaction log for the database is full” 问题及解决办法

DB2在执行一个大的insert/update操作的时候报"The transaction log for the database is full.. "错误,查了一下文档是DB2的日志文件满了的缘故. 首先运行下面命令来查看DB2的日志配置信息 $ db2 get db cfg | grep LOG 注意其中的下面配置项 Log file size (4KB) (LOGFILSIZ) = 1024 Number of primary log files (LOGPRIMARY) =

[转]How expensive are page splits in terms of transaction log?

How expensive are page splits in terms of transaction log? By: Paul Randal Page splits are always thought of as expensive, but just how bad are they? In this post I want to create an example to show how much more transaction log is created when a pag

SQL Server Transaction Log Truncate && Shrink

目录 什么是事务日志 事务日志的组成 事务日志大小维护方法 Truncate Shrink 索引碎片 总结 什么是事务日志 Transaction log   是对数据库管理系统执行的一系列动作的记录,并利用这些记录来保证在遭遇硬件故障,灾难情况下ACID的可用性.从物理上来说,事务日志就是一个记录对数据库更新操作的文件. 事务日志的组成 SQL Server 数据库引擎在内部将每个物理文件分为多个虚拟日志文件.虚拟日志文件没有固定大小和固定数量,这两个值是由数据库引擎动态决定的. 事务日志是一

About Transaction Log

Q1.Why the log space cannot grow even if the recovery mode is full-recovery? A: This is because that the full-recovery mode takes effect only when the user set the full-recovery mode and do the full-backup operation.  This means that, when user creat

测试用的数据库Transaction Log太大, 用于缩减它的脚本

记在这里, 备用. select name, recovery_model_desc from sys.databases where name = 'WSS_Content_1000' USE WSS_Content_1000 ; ALTER DATABASE WSS_Content_1000 SET RECOVERY Simple; go use WSS_Content_1000 go checkpoint go checkpoint go dbcc shrinkfile(WSS_Conte

mysql忘记root密码或报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘xx‘

有的时候忘记了root密码或其他用户的密码,登录的时候报错:ERROR 1044 (42000): Access denied for user ”@’localhost’ to database 'xx'.下面是具体的解决方法: 1.关闭mysql #service mysqld stop 2.屏蔽权限 # mysqld_safe --skip-grant-table 3.新开起一个终端输入 # mysql -u root mysql # mysql> UPDATE user SET Pass

通过Transaction Log(fn_dblog)取回被删除的数据

最近跟 James 讨论为何「ApexSQL Log」这个工具可以读到被删除的数据呢? 原来它是透过 Transaction Log 来读取数据的! 于是透过 Transaction Log 到网络上有找到「SQL Server – How to find Who Deleted What records at What Time」直接透过 Transaction Log 来把被删除的数据给找回来! 蛮神奇的,只是Run在我的区分大小写的DB中会发生错误,因为有些字段名称大小写没有一致,于是就调