Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Removing log information from log file by using DBCC SHRINK FILE Expand / Collapse
Author
Message
Posted Wednesday, August 14, 2013 8:36 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, December 15, 2014 12:39 AM
Points: 104, Visits: 412
Hi All,

Can we remove log information from log file using DBCC SHRINK FILE( 'Logicalname', EmptyFile). Can any body please advise !!!!
Post #1484334
Posted Wednesday, August 14, 2013 8:41 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
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 2008, MVP
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

Post #1484336
Posted Monday, August 19, 2013 3:55 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 9:53 AM
Points: 3,475, Visits: 584
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

Post #1486036
Posted Monday, August 19, 2013 4:04 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:13 AM
Points: 40,609, Visits: 37,070
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 2008, MVP
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

Post #1486043
Posted Monday, August 19, 2013 4:16 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 9:53 AM
Points: 3,475, Visits: 584
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

Post #1486051
Posted Monday, August 19, 2013 4:25 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: 2 days ago @ 11:06 AM
Points: 557, Visits: 1,648
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
Post #1486055
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse