DX UIM (Nimsoft) customers sometimes need to check if data_engine partitioning is working or not, i.e., if partitions are being dropped as expected.
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO
DECLARE @lTableName varchar(max) = 'RN_QOS_DATA_0001';
WITH PartitionInfo AS (
SELECT o.name AS TableName,
p.partition_number AS PartitionNumber,
p.Rows,
CONVERT(datetime, prv.value) AS PartitionValue
FROM sys.objects o
JOIN sys.indexes i ON o.object_id = i.object_id AND i.index_id = 1
JOIN sys.partitions p ON p.object_id = i.object_id AND p.index_id=i.index_id
JOIN sys.partition_schemes ps ON i.data_space_id=ps.data_space_id
LEFT JOIN sys.partition_range_values prv ON ps.function_id=prv.function_id AND prv.boundary_id+1=p.partition_number
WHERE o.name like @lTableName
)
SELECT TableName,
PartitionNumber,
Rows,
'Partition Range' = CASE
WHEN PartitionValue IS NULL THEN
'< ' + CONVERT(varchar(10), (SELECT MIN(PartitionValue) FROM PartitionInfo), 120)
ELSE
'>= ' + CONVERT(varchar(10), PartitionValue, 120) + ' and < ' + CONVERT(varchar(10), DATEADD(DD, 1, PartitionValue), 120)
END,
'Days From Today' = ISNULL(
CASE CONVERT(nvarchar(5), DATEDIFF(day, SYSDATETIME(), PartitionValue))
WHEN '0' THEN '0 *** TODAY ***'
ELSE CONVERT(nvarchar(5), DATEDIFF(day, SYSDATETIME(), PartitionValue))
END,
NCHAR(8734)
)
FROM PartitionInfo
GROUP BY TableName, PartitionNumber, Rows, PartitionValue
ORDER BY PartitionNumber ASC;
-------------------------------------------------------------------------------------
Example output:
How to manually partition the UIM Database for Microsoft SQL Server
Note that all of the proposed guidelines/recommendations included in this Article and document MUST be discussed with a DBA first before taking any action/making any changes to the database.
************Warning Use at your own Risk************
Please review this KB Article and all queries with your DBA before following the steps.
We also highly recommend that these queries and their results be tested in a Test/DEV environment before running in Production.
When enabling partitioning in an environment with a very large database, it is normally advisable to manually partition the largest tables before allowing the data_engine to partition the smaller ones; the data_engine may otherwise 'time out' during maintenance periods if it is allowed to attempt partitioning the tables on its own.