SQL 日志和活动事务
我有一个带有 SQL 2008 的 Web 服务器,运行模拟的 SQL 2005 数据库,并且我有一个用于测试环境的本地 SQL 2005 数据库。
这导致我使用备份/恢复数据脚本进行测试,因为 2008 年服务器备份无法恢复到 2005 年服务器。
当我运行此 SQL 查询以减小生产 Web SQL Server (2008) 上表的大小时,
DELETE FROM TickersDay
WHERE (DATEDIFF(day, TickersDay.[date], GETDATE()) >= 8)
GO
我收到此消息:
Msg 9002, Level 17, State 4, Line 3
The transaction log for database 'VTNET' is full. To find out why space in the log
cannot be reused, see the log_reuse_wait_desc column in sys.databases
当我有时发布脚本时也会出现此消息。
当我运行此 SQL 命令时,我得到以下结果:
SELECT [name], recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
RESULT:
[name] recovery_model_desc log_reuse_wait_desc
VTNET SIMPLE ACTIVE_TRANSACTION
Here are my questions and issues:
- I get it.. 我有一个事务语句需要回滚命令
<如果@@Trancount > 0 回滚> ..但我有 100 个存储过程,所以在我这样做之前....
同时...我怎样才能根除这个问题?我已经尝试过收缩并且我已经尝试过备份数据库...
如您所见,它处于简单模式...我不知道如何备份仅日志文件...(还没有找到了如何做到这一点)...
I have a Web Server with SQL 2008 running a simulated SQL 2005 db, and I have a local SQL 2005 db for testing environment.
This causes me to use scripts for backup/restoring data for testing as 2008 server backups do not restore to a 2005 server.
When I run this SQL Query to reduce the size of a Table on my production Web SQL Server (2008)
DELETE FROM TickersDay
WHERE (DATEDIFF(day, TickersDay.[date], GETDATE()) >= 8)
GO
I get this message:
Msg 9002, Level 17, State 4, Line 3
The transaction log for database 'VTNET' is full. To find out why space in the log
cannot be reused, see the log_reuse_wait_desc column in sys.databases
It comes up when I publish scripts also at times.
When I run this SQL Command I get the following Result:
SELECT [name], recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
RESULT:
[name] recovery_model_desc log_reuse_wait_desc
VTNET SIMPLE ACTIVE_TRANSACTION
Here are my questions and issues:
- I get it.. I have a transaction statement that needs a Rollback Command
< if @@Trancount > 0 Rollback > .. but I have 100 stored procedures so before I do that....
IN THE MEANTIME... how can I eradicate this issue?? I have tried SHRINKING and I have tried backuping up the Db...
As you can see, it is in SIMPLE mode... I do not have any idea how to backup a LOG ONLY file... (have not found how to do that)...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您也许可以通过仅在需要删除的日期上使用索引来让 SQL NOT 处理整个表来解决此问题。将其改写为索引友好
如果您运行得足够频繁(至少每天),那么它只需通过 TickersDay([Date]) 上的索引处理 1/9 或更少,而不必在使用时遍历整个表场上的 DATEDIFF。
如果仍然导致此问题:
您确实需要增加日志大小,因为我怀疑它没有设置为自动增长并且对于此操作来说不够大。或者开始考虑批量删除(再次假设您有日期索引,因此这有效地仅针对 100 行),例如
您可以循环它(当 @@rowcount > 0 时)或者只是更频繁地安排它作为滴流背景删除。
You might be able to get around this issue simply by getting SQL NOT to process the entire table by use the index on only the dates required to be deleted. Rephrase it to be index friendly
If you run this frequently enough (at least daily) then it only has to process 1/9th or less via an index on TickersDay([Date]) instead of having to go through the entire table if you use DATEDIFF on the field.
If that still causes this:
You really need to increase the Log size because I suspect it is not set to autogrow and is not big enough for this operation. Either that or start looking at batching the deletes (again assuming you have an index on date, so this efficiently targets only the 100 rows), e.g.
You can either loop it (while @@rowcount > 0) or just schedule it more frequently as a trickling background delete.