Reputation: 968
I have a little problem :(, I have a data base that reached 1000 partitions for one partition_schema, taking a look on the internet I found that it is the top but it can be increased to 15000. I can't increase it to 15000, the solution that I can do is merge some partitions.
I have a partition by day since 20100101 and actually there is 999, it can't increase anymore, so I want to merge the partitions from one month, but before that I want to do a backup of the information that is going to be affected, BUT I don't know which tables are affected by the function that has 999 ranges.
Q. How can I find out wich tables are affected by the function? or which is the best way to asure that merging the partitions I won't lose data?
Upvotes: 0
Views: 71
Reputation: 3695
You shouldn't lose data merging partitions. Create a backup though, just in case.
Here's a query that can give you some insight into what tables are using the partition function:
DECLARE @PartitionFunction sysname = 'YourPartitionFunctionName';
SELECT t.name TableName
, pf.name PartitionFunction
, ps.name PartitionScheme
, pst.partition_number
, pst.used_page_count
, row_count
from sys.dm_db_partition_stats pst
JOIN sys.partitions p ON pst.partition_id = p.partition_id
JOIN sys.tables t
ON p.object_id = t.object_id
JOIN sys.indexes i
ON p.object_id = i.object_id
AND p.index_id = i.index_id
JOIN sys.allocation_units au
ON p.hobt_id = au.container_id
JOIN sys.filegroups f
ON au.data_space_id = f.data_space_id
JOIN sys.partition_schemes ps
ON ps.data_space_id = i.data_space_id
JOIN sys.partition_functions pf
ON ps.function_id = pf.function_id
WHERE used_page_count > 0
AND pf.name = @PartitionFunction
AND pst.index_id IN (0,1)/*Remove Nonclustered index counts*/;
You can also refer to my answer here for a table valued function that I use regularly for monitoring partition volume.
Upvotes: 2