Database/MS-SQL

[스크랩] 로그백업 수행해도 log_reuse_wait_desc 값이 LOG_BACKUP인 이유

99iberty 2017. 11. 16. 15:07

https://www.sqlskills.com/blogs/paul/why-is-log_reuse_wait_desc-saying-log_backup-after-doing-a-log-backup/



log_reuse_wait_desc 값은 마지막 로그 clear 시도가 어떤 VLF들도 clear하지 않은 이유를 리턴한다.

(the value returned is the reason that log clearing did not clear any VLFs that last time that log clearing was attempted.)


예를 들어 FULL백업이 끝났는데도 ACTIVE_BACKUP_OR_RESTORE 값이 뜨는 경우,,

이 값은, 마지막 log clearing이 시도됐을 당시에 백업이 running 중이었다 라는 것을 의미한다.

For instance, you may see a value of ACTIVE_BACKUP_OR_RESTORE but you know that your full backup has completed. This means that the last time log clearing was attempted, the backup was still running.

즉, 현재 로그의 상태가 아니라 마지막 log clear 당시의 상태를 의미함.


트랜잭션 로그가 증가하지 않은 상태에서 정기 로그백업을 시행함에도 여전히 LOG_BACKUP으로 남는 이유는,

이전 로그백업이 수행되었을때 zero VLF가 cleared 됐기 때문이다. (VLF가 clear되지 않았기 때문이다.)

 If you have a transaction log that is not growing, and you’re taking regular log backups, but the log_reuse_wait_desc remains LOG_BACKUP, this is because zero VLFs were cleared when the previous log backup was performed.



어떻게 이럴 수 있는가?


굉장히 적은 데이터 수정이 일어나는 DB가 있다고 가정해보자. 해당 DB의 정기 로그백업 사이에 few log recodrds만 생성되어 걔네가 모두 같은 VLF에 있다고 가정하자. 다음 로그 백업이 수행되어 해당 few log records는 백업하지만, 현재 VLF를 clear할 수 없어서 log_reuse_wait_desc 상태를 없앨 수가 없다.

충분한 데이터가 쌓여서 현재 VLF가 채워지고 다음 VLF가 활성화되자마자, 다음 로그 백업이 그 전 VLF를 지울 수 있게 되며, 그렇게 되면 log_reuse_wait_desc는 NOTHING으로 바뀔 것이다. 다음 로그백업이 현재 VLF를 clear 할 수 없게 되는 경우, 그 경우에도 LOG_BACKUP으로 바뀔 것이다.


Imagine a database where there’s very little insert/update/delete/DDL activity, so in between your regular log backups there are only a few log records generated, and they’re all in the same VLF. The next log backup runs, backing up those few log records, but it can’t clear the current VLF, so can’t clear log_reuse_wait_desc. As soon as there are enough changes in the database that the current VLF fills up and the next VLF is activated, the next log backup should be able to clear the previous VLF and then the log_reuse_wait_desc will revert to NOTHING. Until the next log backup occurs and isn’t able to clear the current VLF, in which case it will go back to LOG_BACKUP again.


그래서 LOG_BACKUP이 진짜 의미하는 바는, " 로그백업이 필요하거나, 백업된 로그레코드들이 모두 현재 VLF에 있어서 cleared될 수 없었다"  이다.

So LOG_BACKUP really means “either you need to take a log backup, or the log records that were backed up were all in the current VLF and so it could not be cleared.”




근데!!! 좀 이상한게...

나의 경우에는... 아... 로그증가 크기가 너무 작아서 그만큼 VLF 크기도 작아졌는데,


음...그것도 아닌데 머지?? 오히려 VLF가 크면 클수록 같은 VLF에 여러 로그 레코드들이 있을 가능성이 높아지는 것 아닌가???

그럼 오히려 나의 경우에 더 cleared될 확률이 높은 것 아닌가? 머지?!?!?!?!?!??!-.- 왜 계속 log backup으로 남아있는거지?!?!?!?



(Check out my Pluralsight online training course: SQL Server: Logging, Recovery, and the Transaction Log.)

Here’s an interesting situation that sometimes crops up: you’re performing log backups, your transaction log isn’t growing, and yet the value of log_reuse_wait_desc in sys.databases for your database says LOG_BACKUP.

What’s going on?

I was actually just teaching this stuff today here in our last class of the year in Chicago.

Firstly, what is log_reuse_wait_desc? It’s a field in sys.databases that you can use to determine why the transaction log isn’t clearing (a.k.a truncating) correctly. Usually you query it when a log file is growing and you want to know why, using code like:

1
2
3
4
SELECT [log_reuse_wait_desc]
    FROM [master].[sys].[databases]
    WHERE [name] = N'Company';
GO

You can read about all the possible values in the Books online topic Factors That Can Delay Log Truncation.

One important thing to bear in mind is that the value returned is the reason that log clearing did not clear any VLFs (Virtual Log Files – see Understanding Logging and Recovery in SQL Server) that last time that log clearing was attempted. For instance, you may see a value of ACTIVE_BACKUP_OR_RESTORE but you know that your full backup has completed. This means that the last time log clearing was attempted, the backup was still running.

Back to the original question. If you have a transaction log that is not growing, and you’re taking regular log backups, but the log_reuse_wait_desc remains LOG_BACKUP, this is because zero VLFs were cleared when the previous log backup was performed.

How can that happen?

Imagine a database where there’s very little insert/update/delete/DDL activity, so in between your regular log backups there are only a few log records generated, and they’re all in the same VLF. The next log backup runs, backing up those few log records, but it can’t clear the current VLF, so can’t clear log_reuse_wait_desc. As soon as there are enough changes in the database that the current VLF fills up and the next VLF is activated, the next log backup should be able to clear the previous VLF and then the log_reuse_wait_desc will revert to NOTHING. Until the next log backup occurs and isn’t able to clear the current VLF, in which case it will go back to LOG_BACKUP again.

So LOG_BACKUP really means “either you need to take a log backup, or the log records that were backed up were all in the current VLF and so it could not be cleared.”

Hope this helps!