Reputation: 35
We serialize data into an xml, put it into a file and then remove that data from database. We call this process 'Archiving'. The issue is we have to log database free space size before archiving and after archiving. We determine free space with a stored procedure
ALTER PROCEDURE [dbo].[SP_USED_SPACE]
AS
BEGIN
declare @reservedpages bigint, @dbsize bigint
select @reservedpages = sum(a.total_pages)
from sys.partitions p join sys.allocation_units a on p.partition_id = a.container_id
left join sys.internal_tables it on p.object_id = it.object_id
select @dbsize = sum(convert(bigint,case when status & 64 = 0 then size else 0 end)) from dbo.sysfiles
SELECT (convert (dec (15,2), @dbsize)) * 8192 / 1048576 as database_size,
(case when @dbsize >= @reservedpages then
(convert (dec (15,2),@dbsize) - convert (dec (15,2),@reservedpages))
* 8192 / 1048576 else 0 end) as free_space
END
But after archiving that procedure returns nearly or exactly the same value as it did before archiving. Well, I can assure that the deleted data was considerable, say several hundreds of rows in several tables.
Screenshot of what is returned before and after archiving
I have already tried:
What could be the reason of such behavior and how do I fix it?
Upvotes: 3
Views: 1368
Reputation: 725
When a table has no clustered index, a DELETE-Statement does not deallocate the pages. So the space cannot be reused by other objects.
There are options you can use to deallocate pages:
Look at MSDN online, Topic Locking Behavior https://msdn.microsoft.com/en-US/library/ms189835(v=sql.120).aspx
Upvotes: 2