Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #142

Merged
merged 9 commits into from
Nov 14, 2023
Merged

Dev #142

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 157 additions & 71 deletions PSBlitz.ps1

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ You can find the all the scripts in the repository's [Resources](/Resources) dir
|`-SQLPass` | The password for the SQL login provided via the -SQLLogin parameter, omit if `-SQLLogin` was not used. |
|`-IsIndepth` | Providing Y as a value will tell PSBlitz.ps1 to run a more in-depth check against the instance/database. Omit for default check. |
|`-CheckDB` | Used to provide the name of a specific database against which sp_BlitzIndex, sp_BlitzCache, and sp_BlitzLock will be ran. Omit to run against the whole instance.|
|`-CacheTop`| Used to specify if more/less than the default top 10 queries should be returned for the sp_BlitzCache step. Only works for HTML output (`-ToHTM Y`). Has no effect on the `recent compilations` sort order.|
|`-OutputDir`| Used to provide a path where the output directory should be saved to. Defaults to PSBlitz.ps1's directory if not specified or a non-existent path is provided.|
|`-ToHTML`| Providing Y as a value will tell PSBlitz.ps1 to output the report as HTML instead of an Excel file. This is perfect when running PSBlitz from a machine that doesn't have Office installed.|
|`-ZipOutput`| Providing Y as a value will tell PSBlitz.ps1 to also create a zip archive of the output files.|
|`-BlitzWhoDelay` | Used to sepcify the number of seconds between each sp_BlitzWho execution. Defaults to 10 if not specified.|
|`-ConnTimeout`| Can be used to increased the timeout limit in seconds for connecting to SQL Server. Defaults to 15 seconds if not specified.|
|`-MaxTimeout`| Can be used to set a higher timeout for sp_BlitzIndex and Stats and Index info retrieval. Defaults to 800 (13.3 minutes)|
|`-MaxTimeout`| Can be used to set a higher timeout for sp_BlitzIndex and Stats and Index info retrieval. Defaults to 1000 (16.6 minutes)|
|`-DebugInfo`| Switch used to get more information for debugging and troubleshooting purposes.|

[*Back to top*](#header1)
Expand Down Expand Up @@ -173,16 +174,18 @@ Execution plans will be saved in the Plans directory under the output directory.

Execution plans file naming convention:
- for plans obtained through sp_BlitzCache - `[SortOrder]_[RowNumber].sqlplan`.
- for plans obtained through sp_BlitzIndex (only available in SQL Server 2019) - `MissingIndex_[MissingIndexNumber].sqlplan`.
- for plans obtained through sp_BlitzIndex (only available in SQL Server 2019 and above) - `MissingIndex_[MissingIndexNumber].sqlplan`.
- for plans obtained through the open transactions check - `OpenTranCurrent_[SPID].sqlplan` and/or `OpenTranRecent_[SPID].sqlplan`.
- for plans obtained through sp_BlitzQueryStore - `QueryStore_[RowNumber].sqlplan`
- for plans obtained through sp_BlitzWho - `RunningNow_[SPID]_[start_time]_[query_plan_hash].sqlplan`. If no query plan hash is returned by sp_BlitzWho, then 0x00 will be used.

[*Back to top*](#header1)

## Usage examples
You can run PSBlitz.ps1 by simply right-clicking on the script and then clicking on "Run With PowerShell" which will execute the script in interactive mode, prompting you for the required input.
Note that parameters like `-DebugMode` and `-OutputDir` are only available in command line mode.
Note that parameters like `-DebugMode`, `-OutputDir`, `-CacheTop`, and `-MaxTimeout` are only available in command line mode.

Otherwise you can navigate to the directory where the script is in PowerShell and execute it by providing parameters and appropriate values.
Otherwise you can navigate in PowerShell to the directory where the script is and execute it by providing parameters and appropriate values.
- Examples:
1. Print the help menu
```PowerShell
Expand All @@ -192,7 +195,7 @@ Otherwise you can navigate to the directory where the script is in PowerShell an
```PowerShell
.\PSBlitz.ps1 Help
```
or (recommended for detailed help info)
or (recommended for detailed and well-structured help info)
```PowerShell
Get-Help .\PSBlitz.ps1 -Full
```
Expand Down
24 changes: 12 additions & 12 deletions Resources/GetDbInfo.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Part of PSBlitz - https://github.com/VladDBA/PSDBInfo
License - https://github.com/VladDBA/PSDBInfo/blob/main/LICENSE
Part of PSBlitz - https://github.com/VladDBA/PSBlitz
License - https://github.com/VladDBA/PSBlitz/blob/main/LICENSE
*/
SET NOCOUNT ON;
SET STATISTICS XML OFF;
Expand All @@ -16,7 +16,7 @@ IF OBJECT_ID(N'tempdb.dbo.#FSFiles', N'U') IS NOT NULL
CREATE TABLE #FSFiles
( [DatabaseID] [SMALLINT] NULL,
[FSFilesCount] [INT] NULL,
[FSFilesSizeGB] [NUMERIC](15, 3) NULL);
[FSFilesSizeGB] [NUMERIC](23, 3) NULL);

/*Cursor to get FILESTREAM files and their sizes for databases that use FS*/
DECLARE @DBName NVARCHAR(128),
Expand All @@ -41,7 +41,7 @@ WHILE @@FETCH_STATUS = 0
INSERT INTO #FSFiles ([DatabaseID],[FSFilesCount],[FSFilesSizeGB])
SELECT DB_ID(),
COUNT([type]),
CAST(SUM([size] * 8 / 1024.00 / 1024.00) AS NUMERIC(15, 3))
CAST(SUM(CAST([size] AS BIGINT) * 8 / 1024.00 / 1024.00) AS NUMERIC(23, 3))
FROM sys.database_files
WHERE [type] = 2
GROUP BY [type];';
Expand All @@ -60,21 +60,21 @@ SELECT d.[name] AS [Database],
ELSE 0
END) AS [DataFiles],
CAST(SUM(CASE
WHEN f.[type] = 0 THEN ( f.size * 8 / 1024.00 / 1024.00 )
WHEN f.[type] = 0 THEN ( CAST(f.size AS BIGINT) * 8 / 1024.00 / 1024.00 )
ELSE 0.00
END) AS NUMERIC(15, 3)) AS [DataFilesSizeGB],
END) AS NUMERIC(23, 3)) AS [DataFilesSizeGB],
SUM(CASE
WHEN f.[type] = 1 THEN 1
ELSE 0
END) AS [LogFiles],
CAST(SUM(CASE
WHEN f.[type] = 1 THEN ( f.size * 8 / 1024.00 / 1024.00 )
WHEN f.[type] = 1 THEN ( CAST(f.size AS BIGINT) * 8 / 1024.00 / 1024.00 )
ELSE 0.00
END) AS NUMERIC(15, 3)) AS [LogFilesSizeGB],
END) AS NUMERIC(23, 3)) AS [LogFilesSizeGB],
l.[VirtualLogFiles],
ISNULL(fs.FSFilesCount, 0) AS [FILESTREAMContainers],
ISNULL(fs.FSFilesSizeGB, 0.000) AS [FSContainersSizeGB],
CAST(SUM(f.size * 8 / 1024.00 / 1024.00) AS NUMERIC(15, 3))
CAST(SUM(CAST(f.size AS BIGINT) * 8 / 1024.00 / 1024.00) AS NUMERIC(23, 3))
+ ISNULL(fs.FSFilesSizeGB, 0.000) AS [DatabaseSizeGB],
d.[compatibility_level] AS [CompatibilityLevel],
d.[collation_name] AS [Collation],
Expand Down Expand Up @@ -130,17 +130,17 @@ SELECT DB_NAME(f.database_id) AS [Database],
f.[physical_name] AS [FilePhysicalName],
f.[type_desc] AS [FileType],
state_desc AS [State],
CAST(( f.size * 8 / 1024.00 / 1204.00 ) AS DECIMAL(15, 3)) AS SizeGB,
CAST(( CAST(f.size AS BIGINT) * 8 / 1024.00 / 1024.00 ) AS NUMERIC(23, 3)) AS [SizeGB],
CASE
WHEN [max_size] = 0
OR [growth] = 0 THEN 'File autogrowth is disabled'
WHEN [max_size] = -1
AND [growth] > 0 THEN 'Unlimited'
WHEN [max_size] > 0 THEN CAST(CAST (CAST([max_size] AS BIGINT) * 8 / 1024.00 / 1024.00 AS NUMERIC(15, 3)) AS VARCHAR(20))
WHEN [max_size] > 0 THEN CAST(CAST (CAST([max_size] AS BIGINT) * 8 / 1024.00 / 1024.00 AS NUMERIC(23, 3)) AS VARCHAR(20))
END AS [MaxFileSizeGB],
CASE
WHEN [is_percent_growth] = 1 THEN CAST([growth] AS NVARCHAR(2)) + N' %'
WHEN [is_percent_growth] = 0 THEN CAST(CAST(CAST([growth] AS BIGINT)*8/1024.00/1024.00 AS NUMERIC(15, 3)) AS VARCHAR(20))
WHEN [is_percent_growth] = 0 THEN CAST(CAST(CAST([growth] AS BIGINT)*8/1024.00/1024.00 AS NUMERIC(23, 3)) AS VARCHAR(20))
+ ' GB'
END AS [GrowthIncrement]
FROM sys.master_files AS f
Expand Down
4 changes: 4 additions & 0 deletions Resources/GetIndexInfoForWholeDB.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
Part of PSBlitz - https://github.com/VladDBA/PSBlitz
License - https://github.com/VladDBA/PSBlitz/blob/main/LICENSE
*/
/*Index Fragmentation Info*/
USE [..PSBlitzReplace..];

Expand Down
12 changes: 6 additions & 6 deletions Resources/GetInstanceInfo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ OPTION(RECOMPILE);

DECLARE @InstanceLevelOption INT;

/*Get the instance-level configuration*/
/*Get SET options from both session and instance*/
SELECT @InstanceLevelOption = CAST([value_in_use] AS INT)
FROM sys.configurations
WHERE [name] = N'user options';

;
WITH OPTCTE
AS (SELECT Options.id,
AS (SELECT Options.[id],
Options.[Option],
Options.[Description],
ROW_NUMBER()
OVER (
PARTITION BY 1
ORDER BY id) AS bitNum
ORDER BY id) AS [bitNum]
FROM (VALUES (1,
'DISABLE_DEF_CNST_CHK',
'Controls interim or deferred constraint checking. - obsolete and should not be on!'),
Expand Down Expand Up @@ -179,16 +179,16 @@ WITH OPTCTE
'Generates an error when a loss of precision occurs in an expression.'),
(16384,
'XACT_ABORT',
'Rolls back a transaction if a Transact-SQL statement raises a run-time error.') ) AS Options(id, [Option], [Description]))
'Rolls back a transaction if a Transact-SQL statement raises a run-time error.') ) AS Options([id], [Option], [Description]))
SELECT [Option],
CASE
WHEN ( @@OPTIONS & id ) = id THEN 'ON'
ELSE 'OFF'
END AS SessionSetting,
END AS [SessionSetting],
CASE
WHEN ( @InstanceLevelOption & id ) = id THEN 'ON'
ELSE 'OFF'
END AS InstanceSetting,
END AS [InstanceSetting],
[Description],
CASE
WHEN [Description] LIKE '%obsolete%' THEN ''
Expand Down
Loading