Hi All,
One of our drive got filled (E: drive) and we decided to shrink the data file from 1.6TB to 500GB.
While trying to shrink the file with didnt work.
USE [dbname]
GO
DBCC SHRINKFILE (N'db_name_dat' , 0, TRUNCATEONLY)
GO
it completed successfully but it didnt release any space to OS.
--then, tried below. its running for more than 2 hours
USE [dbname]
GO
DBCC SHRINKFILE (N'db_name_dat', 512050)
GO
Am I missing anything, what is the best way to shrink or release free space to OS? Previously, we used to have a log table which has taken up all the data and we truncated the table hoping shrink file will release free space to OS but its not.
Please let me know if you have any other ideas to release some space to OS. Do let me know in case if you need any information from me. This exercise we are doing it in our QA env. During the weekend, we have to do it on prod. In Prod, one variable is, the database is part of AG.
Thanks,
Sam
August 28, 2023 at 2:11 pm
The first command might not shrink the file at all, because of the "TRUNCATEONLY" option.
The second command should work, but shrinks can take a long time.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 28, 2023 at 4:08 pm
A shrink that large will take a long time, especially if there's a fair bit of LOBs in the data. Worse yet, you won't be able to see any progress until it's done even if you stop it. It's better to shrink in much smaller steps in a loop because that will also allow you to monitor progress. I typically use steps of only 10GB. The code should be written to be interruptible and restartable.
You can also write the code to do a shrink step and then try to do a truncate to see if you can "get lucky" between steps... especially for something as big as what you're doing.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 28, 2023 at 6:08 pm
There's not a lot of data left in the file, so I'm rather surprised it would take that long to shrink it, since SQL wouldn't need to move that much data around.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
August 28, 2023 at 8:53 pm
Does it make any difference with the on-going open transactions to the database? is it better to do during maintenance windows when there are no incoming connections from the application? In QA env, we have restarted SQL Server and shrink the file to 500GB. It ran successfully as expected release space to OS and took ~30 mins.
Does it make any difference with the on-going open transactions to the database? is it better to do during maintenance windows when there are no incoming connections from the application? In QA env, we have restarted SQL Server and shrink the file to 500GB. It ran successfully as expected release space to OS and took ~30 mins.
Yes... things will most certainly move more slowly on a busy system because locks on pages need to be acquired before the pages can be moved, etc. The other issue is the way the data is distributed on the file. The other issue is that the data distribution in the actual file is likely going to be very different than on a QA system.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 29, 2023 at 12:53 pm
Suggest you create a new file and file group, then move the objects from the old to the new filegroup. this way you won't have all the negative impacts introduced by the notoriously, horrible, almost useless shrink file operation.
😎
A hint, you might want to introduce table compression in the process 😉
August 29, 2023 at 3:52 pm
Just a thought you need to check the number of VLF's and which is the active one, this will indicate whether a shrink is actually possible.
...
August 29, 2023 at 4:00 pm
Just a thought you need to check the number of VLF's and which is the active one, this will indicate whether a shrink is actually possible.
VLFs are Virtual Log Files that do not relate to the data files, some clarifications might be needed!
😎
Questions to ask are
Responses need to be Evidence-Based! 😉
August 30, 2023 at 11:41 am
I stand corrected I was thinking log as I recently had the issue. Apols to OP for confusion.
...
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply