Solved

Updating SQL partition schemes & partition functions

Posted on 2010-11-16
6
705 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 our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
While in ##Table - Help 4 22
Replication failure 1 23
sql query 5 44
T-SQL: problem comparing datetime 4 50
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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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