Solved

Updating SQL partition schemes & partition functions

Posted on 2010-11-16
6
695 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now