User Tools

Site Tools


microsoft:microsoft_sql_server:sql:shrink_vs_truncate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
microsoft:microsoft_sql_server:sql:shrink_vs_truncate [2022/10/18 16:57] petermicrosoft:microsoft_sql_server:sql:shrink_vs_truncate [2022/10/18 17:14] (current) peter
Line 5: Line 5:
 The **shrink** command is used to reduce the physical log file size of a database. The **shrink** command is used to reduce the physical log file size of a database.
  
-  * That can be understood as de-fragmentation, file compaction, and resetting file physical pointers+<WRAP info> 
-  * There is an inherent risk of data loss should this process fails.+**NOTE:**  That can be understood as de-fragmentation, file compaction, and resetting file physical pointers.
  
-Often databases that are setup with the simple recovery model have corresponding backup jobs that would run during non-business hours (e.g. 2AM) as this will automatically shrink log files.+Often databases that are setup with the **simple recovery model** have corresponding backup jobs that would run during non-business hours (e.g. 2AM) as this will automatically shrink log files.
  
   * Hence, manual intervention may not be required for this design choice.   * Hence, manual intervention may not be required for this design choice.
Line 19: Line 19:
     * Hence, specific point-in-time data cannot be instantaneously restored without retrieving certain log files in whole.     * Hence, specific point-in-time data cannot be instantaneously restored without retrieving certain log files in whole.
     * Hence, shrink operations are often necessary for these types of recovery models.     * Hence, shrink operations are often necessary for these types of recovery models.
 +
 +</WRAP>
 +
 +
 +<WRAP important>
 +**WARNING:**  There is an inherent risk of data loss should this process fails.
 +
 +</WRAP>
 +
  
 Here is a sample T-SQL to perform this task on a Full-Recovery-Model database: Here is a sample T-SQL to perform this task on a Full-Recovery-Model database:
Line 37: Line 46:
 The **truncate** command changes the status of one or more virtual log files (VLF) from active to inactive, which marks those files for overwriting or reuse. The **truncate** command changes the status of one or more virtual log files (VLF) from active to inactive, which marks those files for overwriting or reuse.
  
-  * The truncate command can also be substituted with **NO_LOG**, which will purge a database’s transaction log.+<WRAP info> 
 +**NOTE:** The **truncate** command can also be substituted with **NO_LOG**, which will purge a database’s transaction log. 
   * This may be interpreted as actual deletion.   * This may be interpreted as actual deletion.
     * It is notable that sql backup jobs will also automatically truncate log files.     * It is notable that sql backup jobs will also automatically truncate log files.
     * However, such process will not delete files unless **NO_LOG** is specified after the backup job.     * However, such process will not delete files unless **NO_LOG** is specified after the backup job.
 +
 +</WRAP>
  
 Here is a sample T-SQL to perform this task manually: Here is a sample T-SQL to perform this task manually:
microsoft/microsoft_sql_server/sql/shrink_vs_truncate.1666112250.txt.gz · Last modified: 2022/10/18 16:57 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki