Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 How to shrink a 171 GB size SQL 2005 database

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 15:54:47
Hi All,

Few days agao I posted a similar question abpout shrinking a specific database, and the conculusion was that it cannot be shrink. This time it is a different database and the log file is big which make me thin that it can be shrink. Please read below.

I have a 171 GB database. I want to shrink this database as much as possible.

Under SQL Managment studio when I see the property of this database, the size of the database is 174335.94 MB and the space available is 4144.27 MB.

The Files for this database and have following sizes.

MDF size = 14272 KB
NDF size = 82286016 KB
LDF size = 96219712 KB

When i run sp_spaceused I get the following numbers;
DatabaseName: TestDB
DatabaseSize: 174335.94 MB
UnAllocatedSpace: 4144.27 MB
Reserved: 78056560 KB
Data: 64241760 KB
IndexSize: 13774472 KB
Unused: 40328 KB

I dont want to corrupt or lose the data.
Please suggest the best & easist way to reduce the size of this database as much as possible.

Thanks a million for your prompt help.

Zee

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-08 : 16:02:28
Did you try searching how to shrink huge log file in SQLteam.com? There are millions of post there.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 16:03:47
If space available is only 4GB, then it is pointless to attempt to shrink it.

What is the recovery model on this database and how often are you running transaction log backups (if not using SIMPLE recovery model)?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-10-08 : 16:07:09
Do nothing. Unused is only 0.044GB out of 171.00GB. Calculate the percentage.
If you shrink and later need to grow the files, you will almost certainly fragment your files leading to slower system.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-08 : 16:08:59
He needs to shrink only Log file?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 16:17:39
I still wouldn't shrink it until he finds out why it grew to that size. My guess is that there is an "optimizations" job in place that doesn't do it like my script.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 16:32:21
Someone told me to take a fullbackup first, and then try to shrink which will reduce the log size.
Is it true?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 16:33:55
You don't need to take a full backup to shrink a database. You do need to backup the transaction log or truncate it if you want to shrink the tlog. That's if there isn't much free space available inside the file.

Also, shrinking doesn't cause any data loss or corruption as mentioned in your original post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 16:54:42
tkizer,

The transaction log size is 91 GB. I dont want to backup transaction log since I dont have more than 65 GB of space on the disk. But I want to truncate it. How do I truncate transaction log, without hurting the database?

Please suggest.

Zee
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 17:01:21
A transaction log backup should not be 91GB in size if you are backing it up regularly. You never answered my questions in my first post.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 17:06:00
I never backup the TLog, which I should have. Is this is what you asked?
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 17:17:50
tkizer,

Sorry I mistype earlier.

The LDF size is 91 GB. I dont want to backup LDF since I dont have more than 65 GB of space on the disk. But I want to truncate it. How do I truncate LDF (logs), without hurting the database?

Please suggest.

Zee
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 17:25:49
You didn't tell us what recovery model you are using. It is very important that this question be answered.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 17:32:31
The recover model for this database is "bulk-logged".
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 17:34:38
The reason why your transaction log file has grown to this size is because you are using bulk-logged recovery model and are never backing up the transaction log. You must backup the transaction log on a regular basis for both bulk-logged and full recovery models.

The next thing we need answered is what are your data recovery needs. Can you afford to lose all of the data after a full backup? Or do you need point in time restore capabilities? We can't answer these for you as it depends on the criticality of your data and the application's data needs.

We require point in time restore capabilities due to the criticality of our data. We backup our transaction logs every 15 minutes since that's the maximum amount of time we can afford to lose data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-08 : 17:37:08
Strange!! Are you using Bulk-Insert or Reindex job daily ? You need to change your recovery model to simple and shrink LDF files and again back to Full Recovery model or Bulk Logged Recovery model(If you don't want to log those activities). Make sure you take full backup to where you have space after you do it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 17:38:24
This is certainly not strange. This is very predictable since he is not backing up the transaction log ever.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 17:39:20
tkizer,

I cannot afford to lose any data. The free space on the disk is just 65GB, so I dont think I can do a full backup. We are going to increase the size of the disk in a month or so, but not at this point. My whole goal was to reduce the size of this database as much as possible, and I thought that perhaps I can remove the data in the LDF file, but not sure what is the best way without losing data or corrupting the database.

Please suggest.

Thanks,

Zee
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-08 : 17:40:10
You will not lose any data nor will you corrupt anything. I never mentioned running a full backup. You need to read all of my posts again.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-10-08 : 17:40:59
Its because why not Simple Recovery model rather than Bulk-Logged if transaction log aren't being backed up?
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2008-10-08 : 17:41:40
In order to reduce the size of the database, I am OK with setting the recovery model to simple, and can keep it simple for future.
Please suggest best way to reduce the size of the database.
Go to Top of Page
    Next Page

- Advertisement -