how to change log_reuse_wait and log_reuse_wait_desc

老子叫甜甜 提交于 2020-01-25 01:59:53

问题


I have been created new database and the log file groth very past, and I get error mesaage that the log is full due to 'BACKUP'.

I looked in the differences between this Database and other databases in the SERVER, and I seen that in all databases log_reuse_wait is 0 and log_reuse_wait_desc is NOTHING and in my database log_reuse_wait is 0 and log_reuse_wait_desc is LOG_BACKUP.

I want to change this property in my database to 0 and NOTHING. How can I do that?


回答1:


This is a read-only status variable. It tells you why the log cannot be truncated at this point.

You have to remove the cause of that condition instead of just changing the value (which isn't even possible).

Either backup the database log or switch to SIMPLE recovery mode. You should probably read a little on both just to understand the implications.




回答2:


David W.'s script did not quite work for me. (SQL Server 2008 r2)

I needed to modify it slightly. Using the script as is I got the message that there was no such file for database [master]. Alter the DATABASE as David W. recommends and then switch to the target database and run the DBCC SHRINKFILE() command.

Also the first argument to DBCC SHRINKFILE() must be the logical name of the database log file, which is represented in the following script as logical_file_name_for_LOG

USE [master] 
GO  
ALTER DATABASE <db name> SET RECOVERY full  
GO
ALTER DATABASE <db name> SET RECOVERY SIMPLE WITH NO_WAIT;
GO
USE [db name]
GO
DBCC SHRINKFILE('<logical_file_name_for_LOG>', 0, TRUNCATEONLY)



回答3:


i found the solution. even the database is in SIMPLE mode is wait to BACKUP_LOG, so you need to change the recovery mode to FULL and then back to SIMPLE with no wait

USE [master] 
GO  
ALTER DATABASE <db name> SET RECOVERY full  
GO
ALTER DATABASE <db name> SET RECOVERY SIMPLE WITH NO_WAIT;
GO
USE [db name]
GO
DBCC SHRINKFILE('<log file name>', 0, TRUNCATEONLY)



回答4:


I know this is old, but the answers are wrong.
If the database has recovery mode FULL and that is intended, then do not change it to simple.

The log_reuse_wait_desc says what the state is before the log can be reused or shrinked. In this case it is LOG_BACKUP, meaning that, to shrink the transaction log, you need to backup the transaction log first and shrink it or backup the log and let the SQLServer reuse the log space.

A description of the log_reuse_wait_desc states can be found here



来源:https://stackoverflow.com/questions/13519125/how-to-change-log-reuse-wait-and-log-reuse-wait-desc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!