SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Removing log information from log file by using DBCC SHRINK FILE


Removing log information from log file by using DBCC SHRINK FILE

Author
Message
mohan.bndr
mohan.bndr
Mr or Mrs. 500
Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)Mr or Mrs. 500 (512 reputation)

Group: General Forum Members
Points: 512 Visits: 481
Hi All,

Can we remove log information from log file using DBCC SHRINK FILE( 'Logicalname', EmptyFile). Can any body please advise !!!!
GilaMonster
GilaMonster
SSC Guru
SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)

Group: General Forum Members
Points: 226627 Visits: 46330
EmptyFile is only valid when shrinking a data file. It's completely ignored when specified on a log file. Nothing can ever move log records around within a log file.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Yelena Varshal
Yelena Varshal
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9000 Visits: 600
Well, but you can specify a new empty log file. In the past we did it with sp_attach_single_file_db, in this case a new log file is generated. Now you have to use CREATE DATABASE database_name FOR ATTACH instead as indicated in the article for sp_attach_single_file_db

CREATE DATABASE database_name FOR ATTACH has an option to rebuild the log. The ATTACH_REBUILD_LOG automatically creates a new, 1-MB log file as CREATE DATABASE article says.

I used detaching and attaching a database to replace an old big log with a new empty one.

Yelena


Regards,
Yelena Varshal

GilaMonster
GilaMonster
SSC Guru
SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)

Group: General Forum Members
Points: 226627 Visits: 46330
You can, but bear in mind that only works if the database was shut down cleanly before removing the log. Otherwise you'll end up with a database that fails to attach and that you'll need to restore from backup or hack back in to the server and attempt to repair. It also breaks the log chain.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Yelena Varshal
Yelena Varshal
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9000 Visits: 600
Gail,

Yes, of course. There is a few conditions including that the DB has to be read-write. Also CREATE DATABASE article says
FOR ATTACH_REBUILD_LOG requires the following:
A clean shutdown of the database.
All data files (MDF and NDF) must be available.
Important:
This operation breaks the log backup chain. We recommend that a full database backup be performed after the operation is completed. For more information, see BACKUP (Transact-SQL).

One needs to read on the topic and test in Dev first.

Yelena


Regards,
Yelena Varshal

dan-572483
dan-572483
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3619 Visits: 2000
If what you want to do is simply shrink an oversized log file as much as possible, here's what I do:

1) Run a full databases backup
2) Run a transaction log backup (if the DB is Full Recovery Model)
3) Run DBCC SHRINKFILE('logical_log_file_name',1)

This will remove the data from the log file that is no longer needed.

Dan
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search