December 14, 2009 at 6:11 am
I just archived 6,000,000 rows to another server and deleted them from the original server. sp_spaceused on the archive server shows the table takes up about 80 gig, but the free space in the original database only increased by 40 Gig. What could account for the difference ?
December 14, 2009 at 9:32 am
Have you rebuilt all the indexes on the tables that rows were deleted from?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 14, 2009 at 9:54 am
I would lean towards Gail's note. Likely something just hasn't been updated, but once you've deleted the rows, the space is available for reuse. If you've deleted things, the space is there. It could still be in extents/pages, marked as free.
December 14, 2009 at 10:08 am
I haven't had any "quiet time" to rebuild the indexes yet. (I'm running 2005 Standard, so I can't do online rebuilds :crying:)
Would rebuilding actually increase space in the data files ?
December 14, 2009 at 10:24 am
It doesn't increase the space, but it does fix any reporting issues from the deletes.
December 14, 2009 at 11:51 am
homebrew01 (12/14/2009)
Would rebuilding actually increase space in the data files ?
It may well do. Say those deletes have been spread out over the table. You may have large portions of the table that have pages that are mostly free space. They're still allocated to the table (and still have at least one row on them) but they're mostly free space. Rebuild with your usual fill factor and suddenly a table that took say 200 000 pages that were on average 40% full can now take under 100 000 pages.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 14, 2009 at 9:53 pm
Gail... just checking because I'm low on coffee... does that work only if the table isn't a heap?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 15, 2009 at 2:13 am
Partially. Pre-SQL 2008 a heap can't be rebuilt except by creating a cluster on it. A heap can still have the 10% avg usage of pages if the rows deleted were scattered all over. The space should be later reused by new inserts but after the delete the table could be taking much the same space it did before the delete just with lots of free space on the pages.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 15, 2009 at 6:15 am
GilaMonster (12/15/2009)
Partially. Pre-SQL 2008 a heap can't be rebuilt except by creating a cluster on it. A heap can still have the 10% avg usage of pages if the rows deleted were scattered all over. The space should be later reused by new inserts but after the delete the table could be taking much the same space it did before the delete just with lots of free space on the pages.
Thanks Gail... that's kind of the way I remembered it.
@Homebrew... do you have a clustered index on the table you deleted from?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 15, 2009 at 7:44 am
Is it possible that Ghost Cleanup just hasn't run yet?
Inside the Storage Engine: Ghost cleanup in depth
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
December 15, 2009 at 11:52 am
Jeff Moden (12/15/2009)
@Homebrew... do you have a clustered index on the table you deleted from?
I do not have a clustered index, but I have 6 non-clustered indexes.
December 15, 2009 at 1:10 pm
That's a problem. The heap can't be rebuilt, except by putting a cluster on it, and if there are pages partially used in the heap they'll stay partially used until more data is added.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 15, 2009 at 1:50 pm
GilaMonster (12/15/2009)
That's a problem. The heap can't be rebuilt, except by putting a cluster on it, and if there are pages partially used in the heap they'll stay partially used until more data is added.
+1 Gail hit the nail on the head.
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
My Blog | Twitter | MVP Profile
Training | Consulting | Become a SQLskills Insider
Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]
December 15, 2009 at 2:37 pm
GilaMonster (12/15/2009)
That's a problem. The heap can't be rebuilt, except by putting a cluster on it, and if there are pages partially used in the heap they'll stay partially used until more data is added.
So I rebuild the non-clustered indexes and hope for a small improvement ?
December 15, 2009 at 3:56 pm
I'b build a clustered index. You may want to analyze the usage on the table. There may be a useful index that may benefit from being a clustered index instead of a nonclustered index.
Viewing 15 posts - 1 through 15 (of 24 total)
You must be logged in to reply to this topic. Login to reply