Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Shrink T-log - Mirroring enabled.

Posted on 2014-04-12
10
Medium Priority
?
1,015 Views
Last Modified: 2014-05-27
Hi,

I have enabled Mirroring for one of my databases and I cannot shrink the transaction logs on the primary db anymore.

I'm running the following query:

USE DBname
GO
DBCC SHRINKFILE(DBname_log, 0)
BACKUP LOG DBname WITH TRUNCATE_ONLY
DBCC SHRINKFILE(DBname_log, 0)
GO 

Open in new window


I get the following error:

Cannot shrink log file 2 (DBname_log) because all logical log files are in use.

(1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Msg 3048, Level 16, State 1, Line 2
BACKUP LOG WITH TRUNCATE_ONLY cannot operate on database 'DBname' because it is configured for database mirroring.
Msg 3013, Level 16, State 1, Line 2
BACKUP LOG is terminating abnormally.
Cannot shrink log file 2 (DBname_log) because all logical log files are in use.

(1 row(s) affected)
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Open in new window


I then tried to run:

BACKUP LOG [dbname] TO DISK='NULL'
and 
DBCC SHRINKFILE(DBname_log, 15)

Open in new window


It took about 5 minutes but the size is still at 16 gigs.

How can I reduce the tlogs size to 15 meg?

Thanks.
0
Comment
Question by:ezzadin
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 43

Expert Comment

by:Eugene Z
ID: 39997791
what is your sql server ver\edition sp?
as the main idea unless you drop mirror
you will have opened transactions preventing tlog from shrink.
it means in this case you can not shrink




Database Mirroring in SQL Server 2005
http://technet.microsoft.com/library/Cc917680

make sure you run tlog backups often to keep size tlog down
0
 

Author Comment

by:ezzadin
ID: 39997861
Hi,

I'm running MS SQL 2005 64bit.

So the only way is to drop the mirror??
0
 
LVL 43

Expert Comment

by:Eugene Z
ID: 39997863
you may add an another t-log on another drive and limit the current one size too
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:ezzadin
ID: 39997918
If I drop the mirror, do I have to backup and restore the entire database for the mirror again or can I just re-use the database on the backup server?
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39997954
I believe that you'll have to go through the whole process from scratch.

This time, though, look at what you need for your transaction log. You shouldn't really need to shrink it - ever. If you size it right to begin with then it'll not grow. Remember that as it grows it grabs disk space from the File System, so if you continually shrink your t-log - just like any other file - and let it grow again you'll be getting randomly-located pieces of disk space. This will inevitably slow down your system, as it will forever be exercising the heads as it seeks the "next" piece of log file.

hth

Mike
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39997968
How can I reduce the tlogs size to 15 meg?
15MB ?  Are you serious?  And more importantly why are you shrinking them ?  You do realize that is a very bad idea and should only be done in emergencies,  right?
0
 

Assisted Solution

by:ezzadin
ezzadin earned 0 total points
ID: 39998027
I'm running out of space on the server and need to shrink the tlog.

I came across the following on the net and it worked for me:

use [dbname]
checkpoint
BACKUP LOG [dbname] TO DISK =  'C:\dbname'
dbcc shrinkfile(dbname_log,1)
0
 
LVL 51

Accepted Solution

by:
Mark Wills earned 2000 total points
ID: 39998032
Agree...

You really do have to manage the transaction log file size.

Suggest a quick read of : http://www.experts-exchange.com/Database/MS-SQL-Server/SQL-Server-2005/A_657-Managing-the-Transaction-Log-for-the-Accidental-DBA.html

Now, your main problem is the TRUNCATE_ONLY

You really have to do a full transaction log backup first. Allow time for the transactions to be reflected on the mirror. Problem with truncate is it will remove trailing space back to last fully flagged transaction. There might be a ton of empty space, but size is still showing quite large.

Suggest you do the following...
1) open T-SQL window using the DB needing attention
2) run the t-sql CHECKPOINT command
3) do a full database backup (just in case)
4) run another CHECKPOINT command (even thought the db backup is a checkpoint event)
5) run a transaction log backup (with out the truncate option)
6) wait a little for any transactions to tidy
7) now run your shrinkfile (best to use SSMS)
 
In an emergency...

1) remove partner ALTER DATABASE database_name SET PARTNER OFF
2) follow steps 1-5 above
3) change recovery to SIMPLE
4) issue command EXEC sp_dboption database_name, 'trunc. log on chkpt.', true
5) run a CHECKPOINT (and / or backup)
6) use SSMS, right click on DB, go into tasks > shrink > files
7) choose the transaction log file and use shrink with reorg option
8) set a realistic size - if it doesn't shrink immediately then repeat 5 and 6.
9) set recovery mode back to FULL
10) re-establish (rebuild) mirror

Good reading resource : http://technet.microsoft.com/en-us/library/ms190941(v=sql.90).aspx use the drop down to select your version

Suggest you try first method to begin with and the second is really more a brute force approach.

Then make very sure you schedule to run transaction log backups regularly throughout the day - at least start of day, morning tea, midday, afternoon tea, end of day

Hope that helps...
0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 39998038
*laughing*

the "agree" was in response to acperkins. It just took a while to type in my response and didn't see your reply.

which I also happen to agree with :)

but would still follow the extra steps so that the full DB and the Trans Log backups are in synch.

also make sure your "once -off" fix is done in scheduled "down time" otherwise current transactions from active uses can interfere.
0
 

Author Closing Comment

by:ezzadin
ID: 40092483
Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question