I'm using Microsoft SQL Server 2014 - 12.0.4100.1 Enterprise Edition (64-bit) on Windows NT 6.3 (Build 9600: )
I have a 491 GB table with 3.6 billion rows that does not have a primary key. The primary key I wish to add will only cover a single
bigint column which contains unique values. The database has 477 GB of free space, but that's not enough it seems.
Trying to add it fails with the following error:
Could not allocate space for object 'dbo.SORT temporary run storage: 424251614560256' in database '[Redacted]' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.
The database name in the error is the DB to which I'm trying to add the PK, not 'tempdb', which is what I often see in this sort of error.
The command I'm using:
ALTER TABLE REDACTED ADD CONSTRAINT [PK_REDACTED] PRIMARY KEY CLUSTERED ( [RedactedId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO
At first, the command was failing after 8-9 minutes, then my DBA added another data file to the DB on a drive with about 150 GB of free space. Running it a second time failed after 24 minutes. That's progress, but I have no idea how much free space is needed, or how long it will actually take to add this index. There is currently 477 GB free in this database, but that's still not enough to run this sort it seems.
Is there any way to calculate how much space is needed to run this command on 3.6 billion
bigint values? Or is there some other trick that will help this command succeed? What does that large number mean in the error?