Sql-server – Primary file after table partitioning – SQL Server 2014

partitioningsql server 2014

I have a 230GB database without a clustered index that I'm trying to partition into 25 files for efficiency on a hard drive with 460GB of space. I've created the partition function and partition scheme, and I have executed the commands. During the partition process, the 25 files grew to about 230GB as well and the Primary file did not shrink causing the drive to run out of room. Although the query finished, I was left with two errors.

  1. Transaction log disappeared since there was no room due to ACTIVE_TRANSACTION
  2. Could not allocate a new page for database because of insufficient disk space.

I'm trying to figure out if:

  • the partition is successful and that this is an indexing issue.
  • the Primary is still taking up the full 230GB or is it just allocated space that appears used on my drive. If so, can I safely shrink this without fragmentation?
  • there is an issue with the missing transaction log. If not, where is it going?

I've been able to run queries against the database, so it seems fine on the surface. However, I cannot find any more information on the above mentioned problems. In theory, SQL cannot operate without a transaction log, so I am not sure how to proceed.

I only have a single table Europe_Amad which has 130 columns. No primary keys set.

My partition script is as follows:

USE [FTC]
GO
BEGIN TRANSACTION
CREATE PARTITION FUNCTION [FTC_to_NACE](nvarchar(255)) AS RANGE RIGHT FOR VALUES (N'3500', N'3600', N'4100', N'4500', N'4800', N'5500', N'5800', N'6400', N'6800', N'6900', N'7700', N'8400', N'8500', N'8600', N'9000', N'9400', N'9700', N'9900')


CREATE PARTITION SCHEME [FTC_PS1] AS PARTITION [FTC_to_NACE] TO ([FTCC], [FTCD], [FTCE], [FTCF], [FTCG], [FTCH], [FTCI], [FTCJ], [FTCK], [FTCL], [FTCM], [FTCN], [FTCO], [FTCP], [FTCQ], [FTCR], [FTCS], [FTCT], [FTCU])

SET ANSI_PADDING ON

CREATE CLUSTERED INDEX [ClusteredIndex_on_FTC_PS1_636522495640236401] ON [dbo].[Europe_Amad]
([NACE_PRIM_CODE])WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [FTC_PS1]([NACE_PRIM_CODE])


DROP INDEX [ClusteredIndex_on_FTC_PS1_636522495640236401] ON [dbo].[Europe_Amad]

COMMIT TRANSACTION

Best Answer

This might not be a completed answer but I cannot put all these in comment section. Once you edit your question with more information I will edit the answer if required.

I am sure you did not get the exact error message you mentioned in the question. Transaction log disappeared since there was no room due to ACTIVE_TRANSACTION --Did you mean you transaction could not be completed because log file ran out of space?

the partition is successful and that this is an indexing issue.

Use below query to find out details about your partitions.

SELECT 
    OBJECT_NAME(SI.object_id) AS PartitionedTable
    , DS.name AS PartitionSchemeName
    , PF.name AS PartitionFunction
    , P.partition_number AS PartitionNumber
    , P.rows AS PartitionRows
    , FG.name AS FileGroupName
FROM sys.partitions AS P
JOIN sys.indexes AS SI
    ON P.object_id = SI.object_id AND P.index_id = SI.index_id 
JOIN sys.data_spaces AS DS
    ON DS.data_space_id = SI.data_space_id
JOIN sys.partition_schemes AS PS
    ON PS.data_space_id = SI.data_space_id
JOIN sys.partition_functions AS PF
    ON PF.function_id = PS.function_id 
JOIN sys.destination_data_spaces AS DDS
    ON DDS.partition_scheme_id = SI.data_space_id 
    AND DDS.destination_id = P.partition_number
JOIN sys.filegroups AS FG
    ON DDS.data_space_id = FG.data_space_id
WHERE DS.type = 'PS'
AND OBJECTPROPERTYEX(SI.object_id, 'BaseType') = 'U'
AND SI.type IN(0,1)
ORDER BY PartitionedTable, partitionnumber

the Primary is still taking up the full 230GB or is it just allocated space that appears used on my drive. If so, can I safely shrink this without fragmentation?

Run below query to find out how much of 230GB is being used/free.

SELECT  NAME = LEFT(a.NAME, 64) ,
    a.FILEID ,
    [FILE_SIZE_MB] = CONVERT(DECIMAL(12, 2), ROUND(a.size / 128.000, 2)) ,
    [SPACE_USED_MB] = CONVERT(DECIMAL(12, 2), ROUND(FILEPROPERTY(a.name,
                                                          'SpaceUsed')
                                                    / 128.000, 2)) ,
    [FREE_SPACE_MB] = CONVERT(DECIMAL(12, 2), ROUND(( a.size
                                                      - FILEPROPERTY(a.name,
                                                          'SpaceUsed') )
                                                    / 128.000, 2)) ,
    [PERCENT_FREE] = CONVERT(DECIMAL(12, 2), ( CONVERT(DECIMAL(12, 2), ROUND(( a.size
                                                          - FILEPROPERTY(a.name,
                                                          'SpaceUsed') )
                                                          / 128.000, 2))
                                               * 100 )
    / CONVERT(DECIMAL(12, 2), ROUND(a.size / 128.000, 2))) ,
    FILENAME = LEFT(a.FILENAME, 66)
    FROM    dbo.sysfiles a

there is an issue with the missing transaction log. If not, where is it going?

If your database is online (as you mentioned you are able to query the database) your transaction log file is not missing.