SQL Server:孤立文件脚本 ID 文件不在分区架构/索引中。正在返回一个文件 - SQL Server 抛出“非空”错误
SQL Server:孤立文件脚本 ID 文件不在分区架构/索引中。正在返回一个文件,当尝试删除时,SQL Server 会抛出“非空”
a) 我还能对此脚本做些什么来仅返回“孤立”文件 - 与分区架构或索引无关的“孤立”文件组/文件?
b) 如果这足够了,那么当发出 alter db remove file 时,怎么可能返回其中一个文件 - db 抛出“非空”?
b1) 文件/文件组曾经是分区的一部分,但已被合并出来。通过 sql & 验证了这一点通过查看 @partition schemas
b2) 文件显示大小为 128,我观察到这是文件可能的最小大小。
WITH cte_file_relations
AS(
SELECT
related_to_nothing = CASE WHEN dataspaces_n_indexes.data_space_id IS NULL
AND dds.partition_scheme_id IS NULL
AND ds_alloc_units.data_space_id IS NULL
AND dataspaces_n_full_text_indexes.data_space_id IS NULL
THEN 1
ELSE 0 END
--
, [file_group_name] = fg.name
, filegroup_type_desc = fg.type_desc
, [filegroup_is_empty] = CASE WHEN df.data_space_id IS NULL THEN 1 ELSE 0 END
--
, [file_logical_name] = df.name
, [file_phys_name] = df.physical_name
, [file_empty?] = CASE df.size WHEN 128 THEN ''looks empty'' ELSE ''NOT empty'' END
--
, part_of_Partition_Scheme = CASE WHEN dds.partition_scheme_id IS NULL THEN 0 ELSE 1 END
, part_of_index = CASE WHEN dataspaces_n_indexes.data_space_id IS NULL THEN 0 ELSE 1 END
, part_of_full_text_index = CASE WHEN dataspaces_n_full_text_indexes.data_space_id IS NULL THEN 0 ELSE 1 END
, part_of_alloc_units = CASE WHEN ds_alloc_units.data_space_id IS NULL THEN 0 ELSE 1 END
FROM
sys.filegroups fg WITH ( NOLOCK )
LEFT JOIN sys.database_files df WITH ( NOLOCK )
ON fg.data_space_id = df.data_space_id
LEFT JOIN sys.destination_data_spaces dds
ON fg.data_space_id = dds.data_space_id
LEFT JOIN ( SELECT i.data_space_id FROM sys.indexes i GROUP BY i.data_space_id ) dataspaces_n_indexes
ON fg.data_space_id = dataspaces_n_indexes.data_space_id
LEFT JOIN ( SELECT i.data_space_id FROM sys.fulltext_indexes i GROUP BY i.data_space_id ) dataspaces_n_full_text_indexes
ON fg.data_space_id = dataspaces_n_full_text_indexes.data_space_id
LEFT JOIN ( SELECT data_space_id FROM sys.allocation_units GROUP BY data_space_id ) ds_alloc_units
ON fg.data_space_id = ds_alloc_units.data_space_id
)
select *
from cte_file_relations
WHERE related_to_nothing = 1
根据朋友的预感,我去缩小文件,发现总共有 1 mb - 0.88 mb 可用。然后我查看了@其他我预计为空的文件。其中大多数 @ 1 mb 总空间,显示 0.94 mb 可用空间。
SQL Server: orphaned files script id files not in partition schemas/indexes. Is returning a file which when delete is attempted, SQL Server throws saying "not empty"
a) what more could I do to this script to return only "orphaned" files - "orphaned" filegroup / file not related to a partition schema or index?
b) if this is enough, how could it be that one of the files returned, when the alter db remove file is issued - db throws saying "not empty"?
b1) file / filegroup was once part of a partition, but has been merged out. Verified this by sql & by looking @ partition schemas
b2) file shows size of 128, which I have observed as the smallest size possible for a file
WITH cte_file_relations
AS(
SELECT
related_to_nothing = CASE WHEN dataspaces_n_indexes.data_space_id IS NULL
AND dds.partition_scheme_id IS NULL
AND ds_alloc_units.data_space_id IS NULL
AND dataspaces_n_full_text_indexes.data_space_id IS NULL
THEN 1
ELSE 0 END
--
, [file_group_name] = fg.name
, filegroup_type_desc = fg.type_desc
, [filegroup_is_empty] = CASE WHEN df.data_space_id IS NULL THEN 1 ELSE 0 END
--
, [file_logical_name] = df.name
, [file_phys_name] = df.physical_name
, [file_empty?] = CASE df.size WHEN 128 THEN ''looks empty'' ELSE ''NOT empty'' END
--
, part_of_Partition_Scheme = CASE WHEN dds.partition_scheme_id IS NULL THEN 0 ELSE 1 END
, part_of_index = CASE WHEN dataspaces_n_indexes.data_space_id IS NULL THEN 0 ELSE 1 END
, part_of_full_text_index = CASE WHEN dataspaces_n_full_text_indexes.data_space_id IS NULL THEN 0 ELSE 1 END
, part_of_alloc_units = CASE WHEN ds_alloc_units.data_space_id IS NULL THEN 0 ELSE 1 END
FROM
sys.filegroups fg WITH ( NOLOCK )
LEFT JOIN sys.database_files df WITH ( NOLOCK )
ON fg.data_space_id = df.data_space_id
LEFT JOIN sys.destination_data_spaces dds
ON fg.data_space_id = dds.data_space_id
LEFT JOIN ( SELECT i.data_space_id FROM sys.indexes i GROUP BY i.data_space_id ) dataspaces_n_indexes
ON fg.data_space_id = dataspaces_n_indexes.data_space_id
LEFT JOIN ( SELECT i.data_space_id FROM sys.fulltext_indexes i GROUP BY i.data_space_id ) dataspaces_n_full_text_indexes
ON fg.data_space_id = dataspaces_n_full_text_indexes.data_space_id
LEFT JOIN ( SELECT data_space_id FROM sys.allocation_units GROUP BY data_space_id ) ds_alloc_units
ON fg.data_space_id = ds_alloc_units.data_space_id
)
select *
from cte_file_relations
WHERE related_to_nothing = 1
On a friends hunch, I went to go shrink the file and see of 1 mb total - .88 mb free. Then I looked @ other files I expected to be empty. The majority of them @ 1 mb total space, show .94 mb free space.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft Sql Server 中的错误。
请参阅上一篇文章:
http://www.sqlservercentral.com/Forums/FindPost681162.aspx
在我的情况并能够删除该文件。
Bug in Microsoft Sql Server.
See last post on:
http://www.sqlservercentral.com/Forums/FindPost681162.aspx
Tried this in my situation and was able to delete the file.