5

I am trying to delete all files from my database from an unused filegroup. There are two files totaling aroun 1.5TB. I can see that there is now approx 400mb still in these files but I cant see what it is or how to remove it.

select * from sys.allocation_units a --where data_space_id = 6
inner join sys.partitions b on a.container_id = b.hobt_id --type = 1
where data_space_id = 6

--gives me the following result set

SELECT * INTO #tmp_GridResults_1
FROM (
SELECT N'72057781944647680' AS [allocation_unit_id], N'1' AS [type], N'IN_ROW_DATA' AS [type_desc], N'72057777021059072' AS [container_id], N'6' AS [data_space_id], N'0' AS [total_pages], N'0' AS [used_pages], N'0' AS [data_pages], N'72057777021059072' AS [partition_id], N'741132535' AS [object_id], N'9' AS [index_id], N'1' AS [partition_number], N'72057777021059072' AS [hobt_id], N'0' AS [rows], N'0' AS [filestream_filegroup_id], N'0' AS [data_compression], N'NONE' AS [data_compression_desc] ) t;
SELECT [allocation_unit_id], [type], [type_desc], [container_id], [data_space_id], [total_pages], [used_pages], [data_pages], [partition_id], [object_id], [index_id], [partition_number], [hobt_id], [rows], [filestream_filegroup_id], [data_compression], [data_compression_desc]
FROM #tmp_GridResults_1

DROP TABLE #tmp_GridResults_1
GO

x

select * from sys.allocation_units a --where data_space_id = 6
inner join sys.partitions b on a.container_id = b.hobt_id --type = 1
inner join sys.objects c on c.object_id = b.object_id
where data_space_id = 6

--returns nothing

So it appears I have an object in the database with no rows taking up 400mb which has no record in sys.objects

I have tried adding a small file to the filegroup and performing an emptyfile operation on the files I want to remove and then performaing a dbcc shrink emptyfile however i get "page could not be moved because it was deallocated during shrink" The page refers to the object contained in allocation units but not in sys.objects

DBCC checkdb fails with "CREATE FILE encountered operating system error 665 (could not be completed sue to a file system limitation) while attempting to open or create the physical file

Any ideas on how to progress, I would really like to remove these files or at least shrink them down to a much smaller size

1

Try running DBCC UPDATEUSAGE against the database as SQL may be reporting incorrect data on the space used in the database.

See: https://docs.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017

If this alters any space usage metadata then you could retry the EMPTYFILE again, then remove the files if it is successful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.