Note that there are some explanatory texts on larger screens.

plurals
  1. POProgress for DBCC SHRINKFILE
    primarykey
    data
    text
    <p>I have a <strong>database 21 Gb; 20 Gb of them are files (FileStream)</strong> and I have delete all files from the table but when I make a backup the <strong>backup file still 21 GB</strong>.</p> <p>To solve this problem I became the idee "free the unused space".</p> <p>So I'm trying to <strong>shrink</strong> my database like the following:</p> <pre><code>USE Db; GO -- Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE Db SET RECOVERY SIMPLE; GO -- Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (Db, 100); GO -- Reset the database recovery model. ALTER DATABASE Db SET RECOVERY FULL; GO SELECT file_id, name FROM sys.database_files; GO DBCC SHRINKFILE (1, TRUNCATEONLY); </code></pre> <p>If I make a backup for the database after XX minutes then the backup file size is 1 Gb in this way, I can see that the unused space have been successfully cleaned. In other words the above Sql code working properly(<em>Database after XX minutes is schrunk</em>).</p> <hr> <p><strong>The problem</strong> I need to wait until this query(Shrinking operation) is finished so I'm trying to do the following:</p> <pre><code>SELECT percent_complete, start_time, status, command, estimated_completion_time, cpu_time, total_elapsed_time FROM sys.dm_exec_requests </code></pre> <p>I can not find any information about the SHRINKFILE command in results of the above query.</p> <p><img src="https://i.stack.imgur.com/mU1Vs.png" alt="enter image description here"></p> <hr> <p><strong><em>Did I do something wrong? why I can not see the progress of DB shrinking operation?</em></strong></p> <p><strong><em>And my main quesiton is: How can I wait until the SHRINKFILE is finished?</em></strong> For example can I send from my C# code query and in the result of this query I shall get the information that the SHRINKFILE operation is finsihed or not?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload