<commit_before>function Expand-SqlTLogResponsibly
{
<#
	
.SYNOPSIS
This command will help you to automatically grow your T-Log database file in a responsible way (preventing the generation of too many VLFs).
.DESCRIPTION
As you may already know, having a TLog file with too many VLFs can hurt your database performance in many ways.

Example:
    Too many virtual log files can cause transaction log backups to slow down and can also slow down database recovery and, in extreme cases, even affect insert/update/delete performance. 
    References:
        http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/
        http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx
        http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/
    
	In order to get rid of this fragmentation we need to grow the file taking the following into consideration:
        - How many VLFs are created when we perform a grow operation or when an auto-grow is invoked?
    Note: In SQL Server 2014 this algorithm has changed (http://www.sqlskills.com/blogs/paul/important-change-vlf-creation-algorithm-sql-server-2014/)

Attention:
    We are growing in MB instead of GB because of known issue prior to SQL 2012:
        More detail here: 
            http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx
	    and 
            http://connect.microsoft.com/SQLServer/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately
	    or 
            https://connect.microsoft.com/SQLServer/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb

Understanding related problems:
        http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/
        http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx
        http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/
    
Known bug before SQL Server 2012
        http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx
        http://connect.microsoft.com/SQLServer/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately
        https://connect.microsoft.com/SQLServer/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb

.PARAMETER SqlServer 
    Represents the name/ip of the instance where the database(s) that you want to grow exist
     
.PARAMETER Databases
    This is a list of databases that this command will execute against. You can pass one or many. The database parameter can be passed via the pipeline (see examples).
	
.PARAMETER TargetLogSizeMB
    Represents the target size of the log file, expressed in MB.
    
.PARAMETER IncrementSizeMB
    Represents the incremental size of each growth, expressed in MB.
    If you don't provide this parameter, the value will be calculated automatically. Otherwise, the input value will be compared with the suggested value for your target size. If these values differ, you will be prompted to confirm your choice. 

.PARAMETER LogFileId
    If you want to grow additional T-Log files, you can specify the log file number (FileId column from DBCC LOGINFO output). If you do not specify the log file number, only the first T-log file will be processed.
    
.PARAMETER ShrinkLogFile
This command can automatically shrink your log files for you.

.PARAMETER ShrinkSizeMB
The target size of the log file after the shrink is performed.

.PARAMETER BackupDirectory
Backups must be performed in order to shrink the T-log. Designate a location for your backups. If you do not specify the backup directory, the SQL Server's default backup directory will be used. 

.NOTES
    This script will not analyze the actual number of VLFs (use DBCC LOGINFO)
       
Original Author: <NAME> (@ClaudioESSilva)
Requires: ALTER DATABASE permission
Limitations: Freespace cannot be validated on the directory where the log file resides in SQL Server 2005.

dbatools PowerShell module (https://dbatools.io, <EMAIL>)
Copyright (C) 2016 <NAME>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.<commit_msg>Saved with UTF-8 and fixed Cláudio's name.<commit_after>function Expand-SqlTLogResponsibly
{
<#

.SYNOPSIS
This command will help you to automatically grow your T-Log database file in a responsible way (preventing the generation of too many VLFs).

.DESCRIPTION
As you may already know, having a TLog file with too many VLFs can hurt your database performance in many ways.

Example:
    Too many virtual log files can cause transaction log backups to slow down and can also slow down database recovery and, in extreme cases, even affect insert/update/delete performance. 
    References:
        http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/
        http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx
        http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/
    
	In order to get rid of this fragmentation we need to grow the file taking the following into consideration:
        - How many VLFs are created when we perform a grow operation or when an auto-grow is invoked?
    Note: In SQL Server 2014 this algorithm has changed (http://www.sqlskills.com/blogs/paul/important-change-vlf-creation-algorithm-sql-server-2014/)

Attention:
    We are growing in MB instead of GB because of known issue prior to SQL 2012:
        More detail here: 
            http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx
	    and 
            http://connect.microsoft.com/SQLServer/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately
	    or 
            https://connect.microsoft.com/SQLServer/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb

Understanding related problems:
        http://www.sqlskills.com/blogs/kimberly/transaction-log-vlfs-too-many-or-too-few/
        http://blogs.msdn.com/b/saponsqlserver/archive/2012/02/22/too-many-virtual-log-files-vlfs-can-cause-slow-database-recovery.aspx
        http://www.brentozar.com/blitz/high-virtual-log-file-vlf-count/
    
Known bug before SQL Server 2012
        http://www.sqlskills.com/BLOGS/PAUL/post/Bug-log-file-growth-broken-for-multiples-of-4GB.aspx
        http://connect.microsoft.com/SQLServer/feedback/details/481594/log-growth-not-working-properly-with-specific-growth-sizes-vlfs-also-not-created-appropriately
        https://connect.microsoft.com/SQLServer/feedback/details/357502/transaction-log-file-size-will-not-grow-exactly-4gb-when-filegrowth-4gb

.PARAMETER SqlServer 
    Represents the name/ip of the instance where the database(s) that you want to grow exist
     
.PARAMETER Databases
    This is a list of databases that this command will execute against. You can pass one or many. The database parameter can be passed via the pipeline (see examples).
	
.PARAMETER TargetLogSizeMB
    Represents the target size of the log file, expressed in MB.
    
.PARAMETER IncrementSizeMB
    Represents the incremental size of each growth, expressed in MB.
    If you don't provide this parameter, the value will be calculated automatically. Otherwise, the input value will be compared with the suggested value for your target size. If these values differ, you will be prompted to confirm your choice. 

.PARAMETER LogFileId
    If you want to grow additional T-Log files, you can specify the log file number (FileId column from DBCC LOGINFO output). If you do not specify the log file number, only the first T-log file will be processed.
    
.PARAMETER ShrinkLogFile
This command can automatically shrink your log files for you.

.PARAMETER ShrinkSizeMB
The target size of the log file after the shrink is performed.

.PARAMETER BackupDirectory
Backups must be performed in order to shrink the T-log. Designate a location for your backups. If you do not specify the backup directory, the SQL Server's default backup directory will be used. 

.NOTES
This script will not analyze the actual number of VLFs (use DBCC LOGINFO)
       
Original Author: <NAME> (@ClaudioESSilva)
Requires: ALTER DATABASE permission
Limitations: Freespace cannot be validated on the directory where the log file resides in SQL Server 2005.

dbatools PowerShell module (https://dbatools.io, <EMAIL>)
Copyright (C) 2016 Chr<NAME>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not, see <http://www.gnu.org/licenses/>.
{'fraction_non_alphanumeric': 0.07463138759846495, 'fraction_numerical': 0.014441526964249647, 'mean_word_length': 3.6911416390336336, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 6, 'lorem ipsum': 0, 'www.': 16, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385443', 'n_tokens_mistral': 2957, 'n_tokens_neox': 2748, 'n_words': 1061}