I have done partition on my table and set three new file groups but data is being added to both PRIMARY
file
group and one of the new file groups.
I have got a large table in my database called Sessions
.
I have created three new file groups FG_SESSION_1
, FG_SESSION_2
and FG_SESSION_3
and
each of these file group has two files.
--create new file groupsALTERDATABASE Partition_Test ADD FILEGROUP FG_SESSION_1;
GOALTERDATABASE Partition_TestADDFILE(
NAME = N'fg_session_1_dat1',
FILENAME = N'D:\Databases\fg_session_1_dat1.ndf',
SIZE =1MB,
FILEGROWTH =1MB),(
NAME = N'fg_session_1_dat2',
FILENAME = N'F:\Databases\fg_session_1_dat2.ndf',
SIZE =1MB,
FILEGROWTH =1MB)TO FILEGROUP FG_SESSION_1;
GOALTERDATABASE Partition_Test ADD FILEGROUP FG_SESSION_2;
GOALTERDATABASE Partition_TestADDFILE(
NAME = N'fg_session_2_dat1',
FILENAME = N'D:\Databases\fg_session_2_dat1.ndf',
SIZE =1MB,
FILEGROWTH =1MB),(
NAME = N'fg_session_2_dat2',
FILENAME = N'F:\Databases\fg_session_2_dat2.ndf',
SIZE =1MB,
FILEGROWTH =1MB)TO FILEGROUP FG_SESSION_2;
GOALTERDATABASE Partition_Test ADD FILEGROUP FG_SESSION_3;
GOALTERDATABASE Partition_TestADDFILE(
NAME = N'fg_session_3_dat1',
FILENAME = N'D:\Databases\fg_session_3_dat1.ndf',
SIZE =1MB,
FILEGROWTH =1MB),(
NAME = N'fg_session_3_dat2',
FILENAME = N'F:\Databases\fg_session_3_dat2.ndf',
SIZE =1MB,
FILEGROWTH =1MB)TO FILEGROUP FG_SESSION_3;
GO
Then I created a partition function and scheme to partition my Sessions
table
over three file groups.
--create partitionCREATEPARTITIONFUNCTION P_FUN_SESSION_1 (int)AS RANGE LEFTFORVALUES(10,20);
GOCREATEPARTITION SCHEME P_SCH_SESSION_1ASPARTITION P_FUN_SESSION_1TO(FG_SESSION_1, FG_SESSION_2, FG_SESSION_3);
GOCREATENONCLUSTEREDINDEX IX_PARTITION_Sessions_SessionIDON Sessions (SessionID)ON P_SCH_SESSION_1 (OrgID);
All work fine and data is split over three new file groups as mentioned in the partition scheme but I have realised that my data is also being inserted into the original PRIMARY
file
group as well as one of the new file groups.
I ran a query to find out number of rows in each partition and also checked file sizes for each file group. Every time I insert a new row, it is going to both PRIMARY
file
group and one of the new file groups. Any Idea why?
ObjectName | PartitionScheme | FileGroupName |Rows------------|-----------------|---------------|-----------
Sessions | P_SCH_SESSION_1 |PRIMARY|12048592
Sessions | P_SCH_SESSION_1 | FG_SESSION_1 |12046592
Sessions | P_SCH_SESSION_1 | FG_SESSION_1 |1000
Sessions | P_SCH_SESSION_1 | FG_SESSION_1 |1000
I do not have any other table on this database and PRIMARY
data
file size is total of data file sizes for FG_SESSION_1
, FG_SESSION_2
and FG_SESSION_3
What else Do I need to add to make sure my rows are only go to new file groups and not to the PRIMARY
file
group?