DBCC SHRINKFILE operation increases data usage instead - dbcc

First of all, I know it's better not shrink database. But in our situation we had to shrink the data file to claim more space back.
Environment: SQL Server 2005 x64 SP3 Ent running on Windows Server 2003 Enterprise x64.
The database has one single data file and one log file. Before we run DBCC SHRINKFILE, the data file has 640GB, in which 400GB is free, so the data is about 240GB. To speed up the shrink process,we had to defrag the database first then we shrink data file.
However, after we shrinked the database data file using DBCC SHRINKFILE, the data changed to 490GB. How could it happen?

I asked around include Paul Randal. Here's the possible reason:
When I rebuild indexes for those indexes that were dropped, the indexes would not physically removed from data file, they would be put in deferred drop queue, instead they would stay there and would be dropped in batch.

Related

SQL Server 2008 R2 - database file is 10GB, can't shrink it

I've got a database on SQL Server 2008 R2 that has grown to 10GB (log file is tiny). Users cannot work because they get the message about not being able to allocate space, filegroup PRIMARY being full.
Database is in simple mode, the .mdf file is set to unlimited growth, the initial size says 10240MB and when I change it trough the manager it just goes back up.
Naturally shrinking trough Manager or T-SQL DBCC SHRINKFILE or SHRINKDATABASE does not work because of that (IIRC, shrink cannot go below minimal size).
What are my options now?
Create a new filegroup?
Why can't I reduce initial size?
SEE IMAGE

DBCC SHRINKFILE with emptyfile generating filegroup is full errors

I have been using DBCC SHRINKFILE with EMPTYFILE to move data from one secondary data files data to another. There is currently four files in the filegroup and there is over 1TB free of space between those files.
Oddly, I've had the system alert me that the filegroup that these files belongs to is full and that no space could be allocated for a table (user) table.
I've used this numerous times before and never had this happen and some googling couldn't seem to find any other incidents that people had reported. Anybody have any ideas?
Version of SQL Server is 2008R2
I had this exact problem. It turned out that a nightly maintenance process was issuing an ALTER INDEX command on an index in the same file while the DBCC SHRINKFILE WITH EMPTYFILE was running. Makes sense that ALTER INDEX wouldn't work while the file is marked to not accept new data.
In our environment, we resolved this by preventing the nightly maintenance process from issuing this command and issuing it manually outside of the time that we allow the SHRINKFILE to run.

Shrinking database in SQL Server

I have shrink the large database. I have shrink the database log using SSMS and by query both way. on the properties it is showing the reduced size. But on the drive where it is mounted showing the previous size. What can I do to release the space after shrink of database?
After you shrink database and see the database size is reduced to release the unused empty space to file system, you can execute DBCC SHRINKDATABASE command with TRUNCATEONLY option once more

Database size bigger after delete from table

After I delete huge amount of data from a SQL Server database table, the database size increased.
When I run sp_spaceused it shows me 2625.25 MB. It used to be ~ 1800.00 MB before I deleted from table.
Is there any specific reason it keeps growing even if I delete data?
A temporary transaction log is often the reason for a notable increase of size after a huge delete.
It will eventually disappear on its own but you may remove the files if you need to reclaim the space.
I'm assuming that you are using SQL Server (sp_spaceused). Deleting is logged, so your log file has grown.
See SQL Server 2008 log will not truncate on how to truncate your log (depending on your DB and recovery model), and then you can run
DBCC SHRINKFILE(N)
to reclaim lost space
Edit As per #Aaron, Truncating is also a logged operation. Answer corrected.

SQL server cleaning up databases, transaction logs?

I have a SQL Server 2005 database from which I'm removing several large tables to an archive database. The original database should shrink considerably.
To make the archive database, I was going to restore a copy of the original and just remove the current tables from that.
Is this the best way to go about it? What should I do with logs/shrinking to make sure the final sizes are as small as possible? The archive database may grow a little, but the original continues its normal growth.
That seems like an ok way to do it. Set the recovery model to simple, then truncate and shrink the log files. This will make it as small as possible.
See here for a good way to do it.
Note: This assumes you don't want or need to recover the archive database back to specific points in time. The reason being that Simple recovery model does not save the transactions in a transaction log. So as your archive database changes "a little" (as you said), it won't save the transactions to a log.
I use this script and this is very useful in developing.
BACKUP log [CustomerServiceSystem] with truncate_only
go
DBCC SHRINKDATABASE ([CustomerServiceSystem], 10, TRUNCATEONLY)
go
Redesign the db
Try one of these sql commands:
DBCC SHRINKDATABASE
DBCC SHRINKFILE
Or right click into Sql Server Management Studio Object Explorer's database and select Tasks-Shrink.

Resources