• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Question For Nightman Shrinking MSSQL 2000 and 2005 Databases

Issue:
I have several databases that are in the 7 + GB range.  The log files will grow to over 7 + GB.  I'm trying to develop a VB6 application shrink these databases.

These databases are in MSSQL 2000 and MSSQL 2005


The NO_LOG and TRUNCATE_ONLY options of the BACKUP LOG statement will be removed in a future version of SQL Server. These options break the log chain, because they remove the inactive part of the log without making a backup copy of it and truncate the log by discarding all but the active log. Until the next full or differential database backup, the database is not protected from media failure. Therefore, we strongly recommend that you avoid using either of these options in new development work, and that you plan to modify applications that currently use it


If you
Backup the DATA file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -VrfyBackup -BkUpMedia DISK -BkUpDB "c:\junk_1" -BkExt "BAK"'

Backup the LOG file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -BkUpMedia DISK -BkUpLog "c:\junk_1" -BkExt "TRN"'

Then do a
USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development_Log,5)

Does the 5 limit the size of the log file or just shrink it to 5 meg if possible?

Does this break the log chain or could you restore the database and then restore the log file

or how wound you recommend shrinking the log file.
0
Phil Chapman
Asked:
Phil Chapman
  • 4
  • 4
1 Solution
 
SireesCommented:
<<Does the 5 limit the size of the log file or just shrink it to 5 meg if possible?>>
<<DBCC SHRINKFILE(cax_Development_Log,5) >> 

It shrinks the size of the file named cax_Development_Log to 5MB.

< could you restore the database and then restore the log file
>>

Yes.
A log shrink operation removes enough inactive virtual logs to reduce the log file to the requested size.
0
 
Phil ChapmanAuthor Commented:
What happens if you have the the DBCC SHRINKFILE(cax_Development_Log,5)  but you have 8 meg of active virtual logs
0
 
Scott PletcherSenior DBACommented:
SQL leaves it at 8M.  SQL will never destroy log data because of a SHRINKFILE.


>> The NO_LOG and TRUNCATE_ONLY options of the BACKUP LOG statement will be removed in a future version of SQL Server. <<

Don't hold your breath waiting for it to happen :-) .
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Phil ChapmanAuthor Commented:

If you
Backup the DATA file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -VrfyBackup -BkUpMedia DISK -BkUpDB "c:\junk_1" -BkExt "BAK"'

Backup the LOG file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -BkUpMedia DISK -BkUpLog "c:\junk_1" -BkExt "TRN"'

Then do a
USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development_Log,5)

Is this a good approach to backup data and log files and then shrink the log files.  Is this ok for MSSQL 2000 and MSSQL 2005
0
 
SireesCommented:
Shrinkfile doesn't empty the log. It will just shrink the physical file size without removing any of
the data inside the file. I.e., it doesn't break a log backup chain.

I think you shouldn't shrink a logfile on a regular basis - that will only lead to poor performance because it will have to grow again, and the file will most likely be fragmented as well.

Try to have a look at -
http://www.karaszi.com/SQLServer/info_dont_shrink.asp.

From BOL -

If you backup the log files with TRUNCATE_ONLY then ir removes the inactive part of the log without making a backup copy of it and truncates the log. This option frees space. After backing up the log using either NO_LOG or TRUNCATE_ONLY, the changes recorded in the log are not recoverable. For recovery purposes, immediately execute BACKUP DATABASE.
0
 
Phil ChapmanAuthor Commented:
I beleave i understand it better now.  See if this is correct

You should only shrink the LOG file if for some reason it grows unusually large.  
Example if a similar database log file is 5 MB  and for some reason this one is 11 MB
You would

Backup the DATA file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -VrfyBackup -BkUpMedia DISK -BkUpDB "c:\junk_1" -BkExt "BAK"'

EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00E5FF63BC4F -BkUpMedia DISK -BkUpLog "c:\junk_1" -BkExt "TRN"'


USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development_Log,5)    which is the normal size

If your log file is set to 5 but you only have 3 meg of data the performance will be better than it would if the file had to expand.

We always do complete backups so eventhough TRUNCATE_ONLY invalidates the log file.  If the data and log backup was done at the same time.

And then
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
is run new changes made to the database should be reflected in the Log file.

Is this understand correct?





0
 
SireesCommented:
<<And then
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
is run new changes made to the database should be reflected in the Log file.

Is this understand correct?
>>

Yes.

You just take a full backup and then transaction log backups to reflect the changes made after full backup.

Unless, otherwise needed you don't have to Shrink the log file.
0
 
Phil ChapmanAuthor Commented:
I think i understand this fairely well.  Just one more item.

What is the purpose of the Log File and how is it used.
0
 
SireesCommented:
<<What is the purpose of the Log File and how is it used.>>

The transaction log is a serial record of all the transactions that have been performed against the database since the transaction log was last backed up. With transaction log backups, you can recover the database to a specific point in time (for example, prior to entering unwanted data), or to the point of failure.

For more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_bkprst_565v.asp
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now