patternsqlMinor
SQL Server 2008 R2 Partitioning - same FileGroup, 1 File, 2 partition_numbers - HELP
Viewed 0 times
samefile2008sqlfilegrouphelppartition_numbersserverpartitioning
Problem
It's my first go at partitioning in SQL Server, I learned from the Brent Ozar guide which is fantastic :)
A few times I have ran into a weird scenario; when I run:
There is the same filegroup showing twice with 2 different partition_numbers, 1 correctly at the end with a range value, the other at the start with a null range_value.
click here for enlarge image
Couple of questions:
-
How is this happening, where have I gone wrong?
-
How do I resolve the issue, that means how to get rid of the one at the start as I already have an empty partition at the beginning.
I've tried deleting the file (worked when it was empty) and filegroup, but filegroup said it couldn't be deleted.
Can someone explain please how this has happened and how to get rid of the partition 2 entry?
A few times I have ran into a weird scenario; when I run:
SELECT *
FROM ph.FileGroupDetail
ORDER BY partition_number
GoThere is the same filegroup showing twice with 2 different partition_numbers, 1 correctly at the end with a range value, the other at the start with a null range_value.
click here for enlarge image
Couple of questions:
-
How is this happening, where have I gone wrong?
-
How do I resolve the issue, that means how to get rid of the one at the start as I already have an empty partition at the beginning.
I've tried deleting the file (worked when it was empty) and filegroup, but filegroup said it couldn't be deleted.
Can someone explain please how this has happened and how to get rid of the partition 2 entry?
Solution
The results indicate at some point an explicit NULL partition boundary was added to the function when the partition scheme
Below is a script that shows how a FG30 partition with the NULL boundary can be created. The NULL boundary might have been added accidentally.
NEXT USED filegroup was set to DailyAlbertFG30. Also, I don't see DailyAlbertFG2 used. Perhaps there was once a partition on that filegroup that was subsequently merged.Below is a script that shows how a FG30 partition with the NULL boundary can be created. The NULL boundary might have been added accidentally.
CREATE PARTITION FUNCTION DailyAlbertPF1 (datetime2(3)) AS RANGE RIGHT FOR VALUES();
GO
CREATE PARTITION SCHEME DailyAlbertPS1 AS PARTITION DailyAlbertPF1 ALL TO ([DailyAlbertFG1]);
GO
CREATE TABLE dbo.FactAgentAlbertPortalSessionEntries
(
DateTimeColumn datetime2(3)
)
ON DailyAlbertPS1(DateTimeColumn);
GO
DECLARE @FileGroupNumber int = 1;
DECLARE @DateTimeBoundary datetime2(3) = '2015-04-15T00:00:00.000';
DECLARE @SQL nvarchar(MAX);
WHILE @DateTimeBoundary <= '2015-05-14T00:00:00.000'
BEGIN
SET @SQL = N'ALTER PARTITION SCHEME DailyAlbertPS1 NEXT USED DailyAlbertFG' + CAST(@FileGroupNumber AS nvarchar(5)) + N';';
EXEC(@SQL);
ALTER PARTITION FUNCTION DailyAlbertPF1() SPLIT RANGE(@DateTimeBoundary);
SET @DateTimeBoundary = DATEADD(day, 1, @DateTimeBoundary);
SET @FileGroupNumber += 1;
END;
--add NULL boundary on DailyAlbertFG30
SET @DateTimeBoundary = NULL;
ALTER PARTITION SCHEME DailyAlbertPS1 NEXT USED DailyAlbertFG30;
ALTER PARTITION FUNCTION DailyAlbertPF1() SPLIT RANGE(@DateTimeBoundary);
GOCode Snippets
CREATE PARTITION FUNCTION DailyAlbertPF1 (datetime2(3)) AS RANGE RIGHT FOR VALUES();
GO
CREATE PARTITION SCHEME DailyAlbertPS1 AS PARTITION DailyAlbertPF1 ALL TO ([DailyAlbertFG1]);
GO
CREATE TABLE dbo.FactAgentAlbertPortalSessionEntries
(
DateTimeColumn datetime2(3)
)
ON DailyAlbertPS1(DateTimeColumn);
GO
DECLARE @FileGroupNumber int = 1;
DECLARE @DateTimeBoundary datetime2(3) = '2015-04-15T00:00:00.000';
DECLARE @SQL nvarchar(MAX);
WHILE @DateTimeBoundary <= '2015-05-14T00:00:00.000'
BEGIN
SET @SQL = N'ALTER PARTITION SCHEME DailyAlbertPS1 NEXT USED DailyAlbertFG' + CAST(@FileGroupNumber AS nvarchar(5)) + N';';
EXEC(@SQL);
ALTER PARTITION FUNCTION DailyAlbertPF1() SPLIT RANGE(@DateTimeBoundary);
SET @DateTimeBoundary = DATEADD(day, 1, @DateTimeBoundary);
SET @FileGroupNumber += 1;
END;
--add NULL boundary on DailyAlbertFG30
SET @DateTimeBoundary = NULL;
ALTER PARTITION SCHEME DailyAlbertPS1 NEXT USED DailyAlbertFG30;
ALTER PARTITION FUNCTION DailyAlbertPF1() SPLIT RANGE(@DateTimeBoundary);
GOContext
StackExchange Database Administrators Q#101368, answer score: 3
Revisions (0)
No revisions yet.