Phil Chapman
asked on
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-00 E5FF63BC4F -VrfyBackup -BkUpMedia DISK -BkUpDB "c:\junk_1" -BkExt "BAK"'
Backup the LOG file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00 E5FF63BC4F -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.
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-00
Backup the LOG file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00
Then do a
USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development
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.
ASKER
What happens if you have the the DBCC SHRINKFILE(cax_Development _Log,5) but you have 8 meg of active virtual logs
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 :-) .
>> 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 :-) .
ASKER
If you
Backup the DATA file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00
Backup the LOG file with
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00
Then do a
USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development
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
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.
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.
ASKER
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-00 E5FF63BC4F -VrfyBackup -BkUpMedia DISK -BkUpDB "c:\junk_1" -BkExt "BAK"'
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00 E5FF63BC4F -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?
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-00
EXEC master.dbo.xp_sqlmaint '-PlanID 4F9F327D-27DD-4505-B016-00
USE cax_Development
BACKUP LOG cax_Development WITH TRUNCATE_ONLY
DBCC SHRINKFILE(cax_Development
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?
<<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.
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.
ASKER
I think i understand this fairely well. Just one more item.
What is the purpose of the Log File and how is it used.
What is the purpose of the Log File and how is it used.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<<DBCC SHRINKFILE(cax_Development
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.