简体   繁体   English

数据库的事务日志已满

[英]The transaction log for the database is full

I have a long running process that holds open a transaction for the full duration.我有一个长时间运行的进程,可以在整个持续时间内保持打开事务。

I have no control over the way this is executed.我无法控制它的执行方式。

Because a transaction is held open for the full duration, when the transaction log fills, SQL Server cannot increase the size of the log file.由于事务在整个持续时间内保持打开状态,因此当事务日志填满时,SQL 服务器无法增加日志文件的大小。

So the process fails with the error "The transaction log for database 'xxx' is full" .因此该过程失败并出现错误"The transaction log for database 'xxx' is full"

I have attempted to prevent this by increasing the size of the transaction log file in the database properties, but I get the same error.我试图通过增加数据库属性中事务日志文件的大小来防止这种情况,但我得到了同样的错误。

Not sure what I should try next.不知道接下来我应该尝试什么。 The process runs for several hours so it's not easy to play trial and error.该过程会运行几个小时,因此试错并不容易。

Any ideas?有任何想法吗?

If anyone is interested, the process is an organisation import in Microsoft Dynamics CRM 4.0.如果有人感兴趣,该过程是Microsoft Dynamics CRM 4.0.

There is plenty of disk space, we have the log in simple logging mode and have backed up the log prior to kicking off the process.有足够的磁盘空间,我们有简单日志模式的日志,并在开始进程之前备份了日志。

-=-=-=-=- UPDATE -=-=-=-=- -=-=-=-=- 更新 -=-=-=-=-

Thanks all for the comments so far.感谢大家到目前为止的评论。 The following is what led me to believe that the log would not grow due to the open transaction:以下是让我相信日志不会因为打开的事务而增长的原因:

I am getting the following error...我收到以下错误...

Import Organization (Name=xxx, Id=560d04e7-98ed-e211-9759-0050569d6d39) failed with Exception:
System.Data.SqlClient.SqlException: The transaction log for database 'xxx' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases

So following that advice I went to " log_reuse_wait_desc column in sys.databases " and it held the value " ACTIVE_TRANSACTION ".因此,按照该建议,我去了“ log_reuse_wait_desc column in sys.databases ”,它保存了值“ ACTIVE_TRANSACTION ”。

According to Microsoft: http://msdn.microsoft.com/en-us/library/ms345414(v=sql.105).aspx根据微软: http://msdn.microsoft.com/en-us/library/ms345414(v=sql.105).aspx

That means the following:这意味着以下内容:

A transaction is active (all recovery models).事务处于活动状态(所有恢复模型)。 • A long-running transaction might exist at the start of the log backup. • 日志备份开始时可能存在长时间运行的事务。 In this case, freeing the space might require another log backup.在这种情况下,释放空间可能需要另一个日志备份。 For more information, see "Long-Running Active Transactions," later in this topic.有关详细信息,请参阅本主题后面的“长时间运行的活动事务”。

• A transaction is deferred (SQL Server 2005 Enterprise Edition and later versions only). • 事务被延迟(仅限 SQL Server 2005 Enterprise Edition 和更高版本)。 A deferred transaction is effectively an active transaction whose rollback is blocked because of some unavailable resource.延迟事务实际上是一个活动事务,其回滚由于某些不可用资源而被阻止。 For information about the causes of deferred transactions and how to move them out of the deferred state, see Deferred Transactions.有关延迟事务的原因以及如何将它们移出延迟 state 的信息,请参阅延迟事务。

Have I misunderstood something?我误解了什么吗?

-=-=-=- UPDATE 2 -=-=-=- -=-=-=- 更新 2 -=-=-=-

Just kicked off the process with initial log file size set to 30GB.刚开始这个过程,初始日志文件大小设置为 30GB。 This will take a couple of hours to complete.这将需要几个小时才能完成。

-=-=-=- Final UPDATE -=-=-=- -=-=-=- 最终更新 -=-=-=-

The issue was actually caused by the log file consuming all available disk space.该问题实际上是由日志文件消耗所有可用磁盘空间引起的。 In the last attempt I freed up 120GB and it still used all of it and ultimately failed.在最后一次尝试中,我释放了 120GB,但它仍然使用了所有空间,最终失败了。

I didn't realise this was happening previously because when the process was running overnight, it was rolling back on failure.我之前没有意识到这会发生,因为当进程在一夜之间运行时,它会在失败时回滚。 This time I was able to check the log file size before the rollback.这次我能够在回滚之前检查日志文件的大小。

Thanks all for your input.感谢大家的意见。

To fix this problem, change Recovery Model to Simple then Shrink Files Log要解决此问题,请将恢复模式更改为简单,然后收缩文件日志

1. Database Properties > Options > Recovery Model > Simple 1.数据库属性 > 选项 > 恢复模式 > 简单

2. Database Tasks > Shrink > Files > Log 2.数据库任务 > 收缩 > 文件 > 日志

Done.完毕。

Then check your db log file size at Database Properties > Files > Database Files > Path然后在数据库属性 > 文件 > 数据库文件 > 路径中检查您的数据库日志文件大小

To check full sql server log: open Log File Viewer at SSMS > Database > Management > SQL Server Logs > Current要检查完整的 sql server 日志:在 SSMS > 数据库 > 管理 > SQL Server 日志 > 当前打开日志文件查看器

我曾经遇到过这个错误,结果是服务器的硬盘驱动器磁盘空间不足。

Is this a one time script, or regularly occurring job?这是一次性脚本,还是定期发生的工作?

In the past, for special projects that temporarily require lots of space for the log file, I created a second log file and made it huge.过去,对于临时需要大量日志文件空间的特殊项目,我创建了第二个日志文件并使其变大。 Once the project is complete we then removed the extra log file.项目完成后,我们删除了额外的日志文件。

Do you have Enable Autogrowth and Unrestricted File Growth both enabled for the log file?您是否为日志文件启用了启用自动增长无限制文件增长 You can edit these via SSMS in "Database Properties > Files"您可以通过 SSMS 在“数据库属性 > 文件”中编辑这些

This is an old school approach, but if you're performing an iterative update or insert operation in SQL, something that runs for a long time, it's a good idea to periodically (programmatically) call "checkpoint".这是一种老派的方法,但如果您在 SQL 中执行迭代更新或插入操作,它会运行很长时间,那么定期(以编程方式)调用“检查点”是个好主意。 Calling "checkpoint" causes SQL to write to disk all of those memory-only changes (dirty pages, they're called) and items stored in the transaction log.调用“检查点”会导致 SQL 将所有这些仅内存更改(脏页,它们被调用)和存储在事务日志中的项目写入磁盘。 This has the effect of cleaning out your transaction log periodically, thus preventing problems like the one described.这具有定期清理事务日志的效果,从而防止出现上述问题。

The following will truncate the log.以下将截断日志。

USE [yourdbname] 
GO

-- TRUNCATE TRANSACTION LOG --
DBCC SHRINKFILE(yourdbname_log, 1)
BACKUP LOG yourdbname WITH TRUNCATE_ONLY
DBCC SHRINKFILE(yourdbname_log, 1)
GO

-- CHECK DATABASE HEALTH --
ALTER FUNCTION [dbo].[checker]() RETURNS int AS BEGIN  RETURN 0 END
GO

If your database recovery model is full and you didn't have a log backup maintenance plan, you will get this error because the transaction log becomes full due to LOG_BACKUP .如果您的数据库恢复模型已满并且您没有日志备份维护计划,您将收到此错误,因为LOG_BACKUP导致事务日志已满。

This will prevent any action on this database (eg shrink), and the SQL Server Database Engine will raise a 9002 error.这将阻止对此数据库执行任何操作(例如收缩),并且 SQL Server 数据库引擎将引发 9002 错误。

To overcome this behavior I advise you to check this The transaction log for database 'SharePoint_Config' is full due to LOG_BACKUP that shows detailed steps to solve the issue.为了克服这种行为,我建议您检查此数据库“SharePoint_Config”的事务日志已满,因为 LOG_BACKUP显示了解决问题的详细步骤。

I met the error: "The transaction log for database '...' is full due to 'ACTIVE_TRANSACTION' while deleting old rows from tables of my database for freeing disk space. I realized that this error would occur if the number of rows to be deleted was bigger than 1000000 in my case. So instead of using 1 DELETE statement, i divided the delete task by using DELETE TOP (1000000).... statement.我遇到了错误:“由于 'ACTIVE_TRANSACTION',数据库 '...' 的事务日志已满,同时从我的数据库表中删除旧行以释放磁盘空间。我意识到如果行数达到在我的情况下,被删除大于 1000000。因此,我没有使用 1 个 DELETE 语句,而是使用 DELETE TOP (1000000).... 语句划分了删除任务。

For example:例如:

instead of using this statement:而不是使用此语句:

DELETE FROM Vt30 WHERE Rt < DATEADD(YEAR, -1, GETDATE())

using following statement repeatedly:重复使用以下语句:

DELETE TOP(1000000) FROM Vt30 WHERE Rt < DATEADD(YEAR, -1, GETDATE())

Try this:试试这个:

USE YourDB;  
GO  
-- Truncate the log by changing the database recovery model to SIMPLE.  
ALTER DATABASE YourDB
SET RECOVERY SIMPLE;  
GO  
-- Shrink the truncated log file to 50 MB.  
DBCC SHRINKFILE (YourDB_log, 50);  
GO  
-- Reset the database recovery model.  
ALTER DATABASE YourDB
SET RECOVERY FULL;  
GO 

I hope it helps.我希望它有帮助。

adding up to the answers above, I also want to mention that, if possible, u can also free up the server to fix this issue.加上上面的答案,我还想提一下,如果可能的话,你也可以释放服务器来解决这个问题。 If the server is already full due to the database overflow, u can delete some unnecessary files from the SERVER where ur DB is built upon.如果由于数据库溢出而导致服务器已满,您可以从构建您的数据库的服务器中删除一些不必要的文件。 At least this temporarily fixes the issue and lets you to query the DB至少这暂时解决了问题并让您查询数据库

My problem solved with multiple execute of limited deletes like我的问题通过多次执行有限删除来解决,例如

Before之前

DELETE FROM TableName WHERE Condition

After之后

DELETE TOP(1000) FROM TableName WHERECondition

Solved: As per the error the free space left the in the drive is not sufficient.解决:根据错误,驱动器中剩余的可用空间不足。 to resolve it either you can extend the drive space or move the MDF/LDF/LOG file to the drive with enough space.要解决它,您可以扩展驱动器空间或将 MDF/LDF/LOG 文件移动到具有足够空间的驱动器。 Note: check the existing path from below steps注意:从以下步骤检查现有路径

Database properties -> Select File option enter image description here数据库属性 -> Select 文件选项在此处输入图像描述

The answer to the question is not deleting the rows from a table but it is the the tempDB space that is being taken up due to an active transaction.问题的答案不是从表中删除行,而是由于活动事务而占用的 tempDB 空间。 this happens mostly when there is a merge (upsert) is being run where we try to insert update and delete the transactions.这主要发生在我们尝试插入更新和删除事务的合并(upsert)正在运行时。 The only option is is to make sure the DB is set to simple recovery model and also increase the file to the maximum space (Add an other file group).唯一的选择是确保数据库设置为简单恢复模式,并将文件增加到最大空间(添加其他文件组)。 Although this has its own advantages and disadvantages these are the only options.尽管这有其自身的优点和缺点,但这些是唯一的选择。

The other option that you have is to split the merge(upsert) into two operations.您拥有的另一个选项是将合并(upsert)拆分为两个操作。 one that does the insert and the other that does the update and delete.一个执行插入操作,另一个执行更新和删除操作。

Here's my hero code.这是我的英雄代码。 I've faced this problem.我遇到过这个问题。 And use this code to fix this.并使用此代码来解决此问题。

 USE master;

    SELECT 
        name, log_reuse_wait, log_reuse_wait_desc, is_cdc_enabled 
    FROM 
        sys.databases 
    WHERE 
        name = 'XX_System';

    SELECT DATABASEPROPERTYEX('XX_System', 'IsPublished');


    USE XX_System;
    EXEC sp_repldone null, null, 0,0,1;
    EXEC sp_removedbreplication XX_System;


    DBCC OPENTRAN;
    DBCC SQLPERF(LOGSPACE);
    EXEC sp_replcounters;



    DBCC SQLPERF(LOGSPACE);

Try this:试试这个:

If possible restart the services MSSQLSERVER and SQLSERVERAGENT .如果可能,重新启动服务MSSQLSERVERSQLSERVERAGENT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据库“ tempdb”的事务日志已满 - The transaction log for database 'tempdb' is full SQL server-数据库的事务日志已满 - SQL server- Transaction log for database is full “数据库的事务日志已满” SQL错误 - “Transaction Log for database is full” SQL error 由于“ ACTIVE_TRANSACTION”,数据库“ tempdb”的事务日志已满 - the transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION 由于“ACTIVE_TRANSACTION”,数据库“tempdb”的事务日志已满 - The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION' 数据库“ tempdb”的事务日志已满:但是仍然创建了表吗? - Transaction log for database 'tempdb' is full: but Table created anyway? SQL Server 2008R2由于&#39;ACTIVE_TRANSACTION&#39;,数据库&#39;MGR&#39;的事务日志已满 - SQL server 2008R2 The transaction log for database 'MGR' is full due to 'ACTIVE_TRANSACTION' SQL SERVER事务日志已满 - SQL SERVER Transaction log full 在日常工作计划的某天,我收到错误消息,由于“ ACTIVE_TRANSACTION”,数据库dbname的事务日志已满 - On a certain day in the daily job schedule i get the error The transaction log for database dbname is full due to 'ACTIVE_TRANSACTION' 由于事务日志文件已满,无法删除记录 - Unable to delete records as the transaction log file is full
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM