Saturday, September 9, 2017

SQL Server 2017: Some changes in transaction log monitoring

If your database is configured with the Full recovery model, the transaction log (.ldf files) stores all the transactions done to the database for recovery purposes.
If you fire certain DML commands, the transaction log can grow in matter of minutes and occupy all your precious disk space, that can lead to new commands not able to be executed against the database.

As a new feature in SQL Server 2017 we will have 2 new commands that can help us to monitor the log usage: sys.dm_db_log_stats and sys.dm_db_log_info

sys.dm_db_log_stats


Usage:

sys.dm_db_log_stats ( database_id ) 

This DMV returns a summary of the information for transaction log files. if used without parameter this will return information of the current database.
This can be helpful in a lot of database administration tasks, for example:
  • Using column log_since_last_log_backup_mb you can fire a tlog backup when the log reaches certain size.
  • With log_backup_time you can know the date of the last log backup.
  • Obtain the VLF count with active_vlf_count.
  • Know the log hold reason with log_truncation_holdup_reason, among other things. 

For a full list of columns returned, please visit the official documentation here 


sys.dm_db_log_info


Usage:

sys.dm_db_log_info ( database_id ) 

This DMV returns the VLF information for the database id specified, or the current database if no parameter is used.
It replaces the DBCC LOGINFO command with a more robust and now, documented option to manage VLF information, besides you can now use in custom query build joining it with other tables or views.

For the full column output an definition, please visit the official documentation here

No comments:

Post a Comment