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

SQL Log file Expand / Collapse
Author
Message
Posted Tuesday, October 30, 2012 6:11 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Monday, October 28, 2013 3:12 PM
Points: 313, Visits: 253
I have 2 log files for a database(D and E drive) and i need to delete one which is in E drive. Can i do it directly or do we have some process before doing that.
Post #1378721
Posted Tuesday, October 30, 2012 9:40 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 7, 2014 8:21 AM
Points: 33, Visits: 325
Make sure all live transactions are stopped , if there is a transaction ongoing and writing to that log file you will not be able to delete the Log.


Jack Vamvas
sqlserver-dba.com
Post #1378857
Posted Tuesday, October 30, 2012 10:35 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:36 AM
Points: 42,765, Visits: 35,863
You can't delete any log file that has any portion of the active log regardless of whether there are any currently running transactions or not (stopping transactions won't change that).

Use DBCC LOGINFO to identify which file the active portion of the log is in (VLFs with a status of 2), when all of those are in one file, you can drop the other with an ALTER DATABASE statement.



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 #1378885
Posted Tuesday, October 30, 2012 12:14 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 9:40 AM
Points: 25, Visits: 135
Hi,

1. Take backup of your databases.
2. Detach your database after closing all active connections
3. Attach the database using SSMS.
4. Delete the log file that's not required from the db details pane.

This should do it. It worked for me!!
Post #1378945
Posted Tuesday, October 30, 2012 1:01 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:36 AM
Points: 42,765, Visits: 35,863
menon.satyen (10/30/2012)
Hi,

1. Take backup of your databases.
2. Detach your database after closing all active connections
3. Attach the database using SSMS.
4. Delete the log file that's not required from the db details pane.

This should do it. It worked for me!!


No, no, no!!!

If the log file is deleted (or not attached), SQL could refuse to reattach the DB because either the database was not cleanly shut down or the log file that was 'not required' contained a portion of the active log.

The correct and safe way to remove a log file is the method I gave. Any form of deleting or not attaching a log can potentially destroy the DB entirely requiring a restore from backup.



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 #1378977
Posted Tuesday, October 30, 2012 1:39 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 8:15 AM
Points: 653, Visits: 1,428
Absolutely a NO, NO! Do not DETACH the database.
Post #1378998
Posted Tuesday, October 30, 2012 2:13 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:36 AM
Points: 42,765, Visits: 35,863
George M Parker (10/30/2012)
Another potential option to use the DBCC SHRINKFILE command with an EMPTYFILE clause to clear out one of the two transaction log files by moving the active portions to the primary log file.


No, it does not.

As Books Online says, shrinkfile with the emptyfile option is for data files. It is used to migrate data pages to other data files in the same filegroup.

Log records cannot be moved by anything. To drop an in-use log, you need to wait until the entire active portion of the log is in the file you want to keep (use DBCC LOGINFO) and then you can simply drop the other file (via alter database or the SSMS GUI), no other commands necessary.

To summarise. Shrinkfile with the emptyfile option is for data files. There is nothing at all that can ever move a log record once it's written into the log file ever.



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 #1379015
Posted Tuesday, October 30, 2012 2:35 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 8:15 AM
Points: 653, Visits: 1,428
I stand corrected and have removed the inaccurate post. Is it possible that technique worked in SQL 2000? I've confirmed exactly what you stated using a copy of the AdventureWorks2008R2 database and the EMPTYFILE clause has no effect on the transactions that exist in the 3rd file. I've confirmed it both with DBCC LOGINFO.

Post #1379032
Posted Tuesday, October 30, 2012 2:57 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:36 AM
Points: 42,765, Visits: 35,863
George M Parker (10/30/2012)
Is it possible that technique worked in SQL 2000?


No.



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 #1379042
Posted Tuesday, October 30, 2012 3:08 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 8:15 AM
Points: 653, Visits: 1,428
Thanks Gail.
Post #1379045
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse