HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlModerate

Shrink a large log file for a "Throw Away" database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
awayfilelogshrinkdatabaselargeforthrow

Problem

I have a copy of my prod database on a development server. I am using it to test a deployment script.

But when I run it, it says that the log file is full.

I checked and it is at 10 GB (Almost the size of the full database).

I don't need this database but for a few more hours (after that it is going to get dropped).

Is there any way to get rid of the log file gracefully? (It seems wrong to just go delete it.)

NOTE:

I have run this:

select log_reuse_wait, log_reuse_wait_desc, name 
from sys.databases
where name = 'ProdCopyDatabase'


And the result is:

log_reuse_wait  log_reuse_wait_desc    name
2               LOG_BACKUP             ProdCopyDatabase

Solution

You have two options:

1) Run a LOG backup of the database:

BACKUP LOG foo TO DISK='X:\BackupLocation';


2) Set the recovery model to SIMPLE and checkpoint it.

ALTER DATABASE foo SET RECOVERY SIMPLE;
CHECKPOINT;


This is all part of SQL Server's different recovery models. Based on you working on this in DEV, I'd probably go the second option since it sounds like you don't need to worry about point in time recovery.

Note, this will simply clear out the active transactions, not reduce the actual file size. Once this is complete, you can then shrink the log file.

Code Snippets

BACKUP LOG foo TO DISK='X:\BackupLocation';
ALTER DATABASE foo SET RECOVERY SIMPLE;
CHECKPOINT;

Context

StackExchange Database Administrators Q#29727, answer score: 14

Revisions (0)

No revisions yet.