Solved

Updating SQL partition schemes & partition functions

Posted on 2010-11-16
6
704 Views
Last Modified: 2012-05-10
My client's IT dept had set up SQL Server 2005 filegroups on a particular database for each fiscal quarter: fg2006Q4, fg2007Q1, fg2007Q2, ... up to fg2010Q4. I noticed today that the fg2010Qx files had not been used, still at 1MB each.

Upon further digging, I found the Partition Schemes and Partition Functions folders in Mgmt Studio.

One Scheme: CREATE PARTITION SCHEME [psEvent] AS PARTITION [pfEvent] TO ([fg2006Q4], [fg2007Q1], [fg2007Q2], [fg2007Q3], [fg2007Q4], [fg2008Q1], [fg2008Q2], [fg2008Q3], [fg2008Q4], [fg2009Q1], [fg2009Q2], [fg2009Q3], [fg2009Q4])

Corresponding Function: CREATE PARTITION FUNCTION [pfEvent](int) AS RANGE RIGHT FOR VALUES (1000300, 5493523, 25712235, 45243827, 67741212, 88804361, 106935897, 121343754, 122508529, 122512053, 139523161, 154878083)

Q1: I'd like to create filegroups for fg2011Qx... then can I simply ALTER PARTITION SCHEME with fg2010Q1 through fg2011Q4 added to the list?

Q2: I believe I understand the function ranges, but wondering where/how these ID's would have been generated (likely)? And more fundamentally, how would SQL know when to move onto the next filegroup (assuming it had existed when needed)?

Q3: Is there a safe & easy way to "re-balance" the filegroups... so that fg2010Qx's are used, and the fg2009Q4's aren't so big. I suppose not a huge deal if not, but it'd look cleaner if so.

Thanks,
Jeff
0
Comment
Question by:jdallen75
  • 3
  • 3
6 Comments
 
LVL 9

Expert Comment

by:Sander Stad
ID: 34153577
You can add an additional filegroup to the scheme with the following command:

ALTER PARTITION SCHEME psEvent
NEXT USED fg2011Qx;
GO

Than you can use the following script to alter the partition function:

IF EXISTS (SELECT * FROM sys.partition_functions
    WHERE name = 'pfEevent')
DROP PARTITION FUNCTION pfEvent;
GO
CREATE PARTITION FUNCTION pfEevent (int)
AS RANGE RIGHT FOR VALUES  (1000300, 5493523, 25712235, 45243827, 67741212, 88804361, 106935897, 121343754, 122508529, 122512053, 139523161, 154878083, xxxxxxx);
GO
0
 
LVL 9

Accepted Solution

by:
Sander Stad earned 500 total points
ID: 34153622
Q2:
The numbers in the function are not ID's but are the boundaries of rows. This website shows you what you want to know: http://msdn.microsoft.com/en-us/library/ms187802(v=SQL.90).aspx

Q3: What do you mean by rebalance the filegroups? Do you want to change the number of records that are saved in the different filegroups?
0
 

Author Comment

by:jdallen75
ID: 34154843
Sstad,

Q3: I mean that, for instance, the files in fg2009Q1, Q2, and Q3 each total 10GB. However, since fg2009Q4 was the last listed in the partition scheme, it has been used since that point in time, and is now 80GB. fg2010Qx files are basically empty because they have not been used this year.

Thanks on the other points - I will look into them.

JA
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:jdallen75
ID: 34155331
I think I understand now... it looks as though the boundary values in the partition function list are SSID's of the rows in the tables. That part isn't all that intuitive, and more importantly does not cleanly divided up the data by calendar quarters. What seems to be cleaner would be to choose a datetime column from the table, and define its boundaries accordingly. "20090101, 20090401, 20090701..." is a heck of a lot clearer!
0
 
LVL 9

Expert Comment

by:Sander Stad
ID: 34157157
That could work but make sure your column is in date or int format because I don't know how it works with text in this case.
0
 

Author Comment

by:jdallen75
ID: 34158841
I discovered the common problem in that the partition column has to be part of the primary key, which in this case it isn't. There are a couple of workaround solutions, be we've decided in this case (since it is an archive DB), to go with one partition over several filegroups.

Thanks for your guidance.
JA
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question