今天查看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 中存在Active Transaction,那么该VLF就不能被截断和重用。如果事务日志文件没有可用的VLF,那么SQL Server就不能处理新增的事务,并抛出事务日志文件耗尽的错误消息。

那为什么Active Transaction 会导致事务日志文件耗尽?

1,如果数据库的事务日志文件太大,将整个Disk Space耗尽,那么就要考虑是什么原因造成事务日志文件大量增长,定期做事务日志备份能够截断事务日志文件。

2,如果数据库的事务日志文件本身不是很大,可能的原因是SQL Server 无法为事务日志文件分配Disk Space。

3,查看数据库中活动的事务,如果是由于一个事务运行时间太长,没有关闭,导致事务日志的VLF不能重用,那么必须修改应用程序。

如果数据库中某一个 Transaction 运行的时间太长,导致其他transaction虽然被commint,但是其占用的VLF仍然被标记为Active,不能被truncate和reuse,当log文件中没有可用的VLF,而SQL Server又要处理新增的Transaction时,SQL Server就会报错。

step1,查看事务日志文件的大小

查看日志文件的 size_gb 和 max_size_gb 字段,发现该事务日志文件的大小没有达到最大值,并且事务日志文件占用的Disk Space并不是很大,我猜想,很可能是日志文件所在的Disk Space 被使用殆尽,没有剩余的free space。

select db.name as database_name,
db.is_auto_shrink_on,
db.recovery_model_desc,
mf.file_id,
mf.type_desc,
mf.name as logic_file_name,
mf.size*8/1024/1024 as size_gb,
mf.physical_name,
iif(mf.max_size=-1,-1,mf.max_size*8/1024/1024) as max_size_gb,
mf.growth,
mf.is_percent_growth,
mf.state_desc
from sys.databases db
inner join sys.master_files mf
on db.database_id=mf.database_id
where mf.size*8/1024/1024>1 -- GB
and db.name='database name'
and mf.type=0
order by size_gb desc

step2,查看Disk的Free Space

查询结果显示,D盘空间仅仅剩下9MB,正是事务日志文件所在的Disk。

exec sys.xp_fixeddrives

step3,Disk Space 用尽,必须想办法将大的数据文件压缩,或者将事务日志文件截断。

由于数据库的恢复模式是simple,会自动截断事务日志文件,因此,最大的可能是disk space耗尽。

1,查看数据库空间的使用情况

exec sys.sp_spaceused

unallocated space 空闲很大,必须压缩数据库,以释放disk space

2,收缩(shrink)数据库文件

use target_database_name
go select file_id,
type,
type_desc,
data_space_id,
name,
size*8/1024/1024 as size_gb,
growth,
is_percent_growth,
physical_name,
max_size
from sys.database_files dbcc shrinkfile('file logcial name',0,notruncate)
dbcc shrinkfile('file logcial name',target_size_mb,truncateonly)

3,对数据库中的 table 和 index 压缩存储
3.1, 查看数据库中,占用存储空间非常大的table;

use target_database_name
go select
t.name,
sum(case when ps.index_id<2 then ps.row_count else 0 end) as row_count,
sum(ps.reserved_page_count)*8/1024/1024 as reserved_gb,
sum(ps.used_page_count)*8/1024/1024 as used_gb,
sum( case when ps.index_id<2
then ps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_count
else 0 end
)*8/1024/1024 as data_used_gb,
sum(case when ps.index_id>=2
then ps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_count
else 0 end
)*8/1024/1024 as index_used_gb
from sys.dm_db_partition_stats ps
inner join sys.tables t
on ps.object_id=t.object_id
group by t.object_id, t.name
order by used_gb desc

3.2, 查看table及其Index是否被压缩过

select p.partition_id,object_name(p.object_id) as ObjectName,
p.index_id,
p.rows,
p.data_compression,
p.data_compression_desc,
au.Type,
au.Type_desc,
au.total_pages,
au.used_pages,
au.data_pages
from sys.partitions p
inner join sys.allocation_units au
on p.partition_id=au.container_id
where p.object_id=object_id('[dbo].[table_name]',N'U')

3.3,估计压缩能够节省的存储空间

exec sys.sp_estimate_data_compression_savings
@schema_name='dbo',
@object_name='table_name',
@index_id=1,
@partition_number=null,
@data_compression ='page'

3.4, 对table及其index进行数据压缩
对table 及其index 进行 rebuild,SQL Server将重新分配存储空间,慎重:rebuild 反而会增加数据库占用的存储空间。在数据压缩存储之后,必须shrink 数据库文件,才能释放数据库所占用的存储空间,增加Disk的Free Space。

alter table [dbo].table_name
rebuild with(data_compression=page) alter index index_name
on [dbo].table_name
rebuild with(data_compression=page)

4,增加事务日志文件

参考:《The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'

Appendix:《Log Reuse Waits Explained: ACTIVE_TRANSACTION

SQL Server will return a log_reuse_wait_desc value of ACTIVE_ TRANSACTION if it runs out of virtual log files because of an open transaction. Open transactions prevent virtual log file reuse, because the information in the log records for that transaction might be required to execute a rollback operation.

To prevent this log reuse wait type, make sure you design you transactions to be as short lived as possible and never require end user interaction while a transaction is open.

To resolve this wait, you have to commit or rollback all transactions. The safest strategy is to just wait until the transactions finish themselves. Well-designed transactions are usually short lived, but there are many reasons that can turn a normal transaction into a log running one. If you cannot afford to wait for an extra-long running transaction to finish, you might have to kill its session. However, that will cause that transaction to be rolled back. Keep this in mind when designing your application and try to keep all transactions as short as possible.

One common design mistake that can lead to very long running transactions is to require user interaction while the transaction is open. If the person that started the transaction went to lunch while the system is waiting for a response, this transaction can turn into a very-long-running transaction. During this time other transactions, if they are not blocked by this one, will eventually fill up the log and cause the log file to grow.

The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'的更多相关文章

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

    今天早上,Dev跟我说,执行query statement时出现一个error,detail info是: “The transaction log for database 'tempdb' is ...

  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_TR ...

  3. Replication:The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'

    今天早上,Dev跟我说,执行query statement时出现一个error,detail info是: “The transaction log for database 'tempdb' is ...

  4. Error: 9001, Severity: 21, State: 5 The log for database 'xxxx' is not available

    昨天下午5点多收到几封告警邮件,我还没有来得及看,GLE那边的同事就电话过来,说数据库出现告警了.让我赶紧看看,案例具体信息如下所示: 告警邮件内容: DATE/TIME: 2015/1/23 17: ...

  5. SQLSERVER事务日志已满 the transaction log for database 'xx' is full

    解决办法:清除日志 USE [master] GO ALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE D ...

  6. Database 'xxxx' is being recovered. Waiting until recovery is finished.

    巡检发现一个SQL SERVER Express 2005数据库备份时出现下面错误: Database 'xxxx' is being recovered. Waiting until recover ...

  7. The log scan number (620023:3702:1) passed to log scan in database 'xxxx' is not valid

    昨天一台SQL Server 2008R2的数据库在凌晨5点多抛出下面告警信息: The log scan number (620023:3702:1) passed to log scan in d ...

  8. DB2 “The transaction log for the database is full” 存在的问题及解决方案

    DB2在执行一个大的insert/update操作的时候报"The transaction log for the database is full.. "错误,查了一下文档是DB ...

  9. SQL Server Transaction Log Truncate && Shrink

    目录 什么是事务日志 事务日志的组成 事务日志大小维护方法 Truncate Shrink 索引碎片 总结 什么是事务日志 Transaction log   是对数据库管理系统执行的一系列动作的记录 ...

随机推荐

  1. C# 向listbox添加大量数据项的实践心得

    使用 ListBox.Items.Add 方法添加项时,可以使用 BeginUpdate 方法,以防止每次向列表添加项时控件都重新绘制 ListBox.完成向列表添加项的任务后,调用 EndUpdat ...

  2. 关于XML中:XmlNode和XmlElement的涵义及不同之处

    今天学习XML,遇到XmlNode和XmlElement俩个类,故有了下文的所述: 今天在做ASP.NET操作XML文档的过程中,发现了两个类:XmlNode和XmlElement.这两个类的功能极其 ...

  3. [机器学习] 深度学习之caffe1——软件配置与测试

    caffe的编译配置真的是很让人头疼啊,不知道试过多少次了~~~ 重装系统了七八次,搞得linux的一些常用命令倒是很熟悉了~~~ 我有洁癖~~~某一个点上出了错,我一定要把它搞好了,再重新来一次,我 ...

  4. 【ORACLE】ORA-12537 问题整理

    ORA-12537主要是ORALCE 监听问题,今天帮同事处理问题时,他问道一种情况,开始连接很正常,后续多次出现ORA-12537问题 简单整理了下 一般请况下 1-检查数据库服务器是否没有启动监听 ...

  5. 一张图系列——为什么在DllMain里面创建了线程并Wait会卡死

    这是一个老话题了,推荐一篇文章: http://blog.csdn.net/breaksoftware/article/details/8150476#0-tsina-1-83826-39723281 ...

  6. tungsten抽取和应用mysql binlog

    首先举例说明 api的基本使用方式 首先进行配置 , 可以看到源数据库和目的数据库 TungstenProperties tp=new TungstenProperties(); tp.setStri ...

  7. linux开启FTP以及添加用户配置权限,只允许访问自身目录,不能跳转根目录

    1.切换到root用户 2.查看是否安装vsftp,我这个是已经安装的. [root@localhost vsftpd]# rpm -qa |grep vsftpd vsftpd--.el7_2.x8 ...

  8. 第一章-第十三题(该游戏团队, 有很好的软件,但是商业模式和其他软件之外的因素有没有考虑到?)--By梁旭晖

    这款软件无疑是一个好软件,软件的开发者是有相当水平的,可以说是优秀的软件编写人员,但是也只是优秀的软件人员,术业有专攻,他们在其他方面我觉得是有很大的欠缺的. 我觉得,他们并没有抓住消费者的心理,首先 ...

  9. 如何在arcmap中调试addin或者插件

    1. 首先,在arcmap中,依次点击“自定义”->"加载项管理器",加载dll或者tlb文件 2. 其次,在vs中,依次点击“工具”->“附加到进程",在对 ...

  10. SQL Server2014 哈希索引原理

    SQL Server2014 哈希索引原理 翻译自:http://www.sqlservercentral.com/blogs/sql-and-sql-only/2015/09/08/hekaton- ...