开发者

What is the use of a transaction log on a read-only database?

In Sql Server, I find that, when I mark a database as read only, its existing large transaction log remains. To fix this I have to set it back to writeable, then dbcc shrinkfile on the log file开发者_开发百科, then set it read-only again.

What is the use of a transaction log if the database is read only? Is there a reason it doesn't just get deleted/flushed?


If your database is still in full recovery mode, the log will not shrink without a proper backup. You should switch your read-only database to simple recovery.

Also, the log file is needed should you ever decide to detach/attach this database. As noted here:

In contrast, for a read-only database, the log cannot be rebuilt because the primary file cannot be updated. Therefore, when you attach a read-only database whose log is unavailable, you must provide the log files or files in the FOR ATTACH clause.


There is no use for a transaction log on a read-only db :-) Assuming you are past some point at which you no longer care about the transactions done to populate it. I imagine it's not flushed because that would not be good default behaviour, imagine if you wanted to go back to write mode? Or you discovered during read-only operation that there was a problem and you needed to use the logs?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜