Skip to content

Commit

Permalink
Merge pull request #9 from amtwo/v21.0
Browse files Browse the repository at this point in the history
V21.0
  • Loading branch information
amtwo authored Apr 27, 2021
2 parents 96c21ee + 8034576 commit 57f0016
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 100 deletions.
15 changes: 11 additions & 4 deletions Get-OpenSourceScripts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $dir = Get-Location

# Ola Hallengren's maintenance scripts
New-Item -Path "$($dir)\oss\olahallengren" -ItemType Directory -Force |Out-Null
$url = "https://ola.hallengren.com/scripts"
$url = "https://raw.githubusercontent.com/olahallengren/sql-server-maintenance-solution/master"
Invoke-WebRequest -Uri "$($url)/CommandExecute.sql" -OutFile "$($dir)\oss\olahallengren\CommandExecute.sql"
Invoke-WebRequest -Uri "$($url)/CommandLog.sql" -OutFile "$($dir)\oss\olahallengren\CommandLog.sql"
Invoke-WebRequest -Uri "$($url)/DatabaseBackup.sql" -OutFile "$($dir)\oss\olahallengren\DatabaseBackup.sql"
Expand All @@ -22,10 +22,17 @@ Invoke-WebRequest -Uri "$($url)/sp_BlitzLock.sql" -OutFile "$($dir)\oss\firstres
#This throws errors when I try to deploy it to <2016 servers. Pulling it for now--will revisit later.
#Invoke-WebRequest -Uri "$($url)/sp_BlitzQueryStore.sql" -OutFile "$($dir)\oss\firstresponderkit\sp_BlitzQueryStore.sql"
Invoke-WebRequest -Uri "$($url)/sp_BlitzWho.sql" -OutFile "$($dir)\oss\firstresponderkit\sp_BlitzWho.sql"
Invoke-WebRequest -Uri "$($url)/Deprecated/sp_foreachdb.sql" -OutFile "$($dir)\oss\firstresponderkit\sp_foreachdb.sql"
Invoke-WebRequest -Uri "$($url)/sp_ineachdb.sql" -OutFile "$($dir)\oss\firstresponderkit\sp_ineachdb.sql"

# sp_WhoIsActive
New-Item -Path "$($dir)\oss\whoisactive" -ItemType Directory -Force |Out-Null
$url = "https://raw.githubusercontent.com/amachanic/sp_whoisactive/master/who_is_active.sql"
Invoke-WebRequest -Uri $url -OutFile "$($dir)\oss\whoisactive\who_is_active.sql"
$url = "https://raw.githubusercontent.com/amachanic/sp_whoisactive/master"
Invoke-WebRequest -Uri "$($url)/who_is_active.sql" -OutFile "$($dir)\oss\whoisactive\who_is_active.sql"


# Darling Data Troubleshooting scripts
New-Item -Path "$($dir)\oss\darlingdata" -ItemType Directory -Force |Out-Null
$url = "https://raw.githubusercontent.com/erikdarlingdata/DarlingData/master"
Invoke-WebRequest -Uri "$($url)/sp_PressureDetector/sp_PressureDetector.sql" -OutFile "$($dir)\oss\darlingdata\sp_PressureDetector.sql"
Invoke-WebRequest -Uri "$($url)/sp_HumanEvents/sp_HumanEvents.sql" -OutFile "$($dir)\oss\darlingdata\sp_HumanEvents.sql"

14 changes: 14 additions & 0 deletions Install-LatestDbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ foreach($instance in $InstanceName) {
Write-Verbose $file.FullName
Invoke-Sqlcmd -ServerInstance $instance -Database $DatabaseName -InputFile $file.FullName -QueryTimeout 300
}
#Then views
Write-Verbose "`n ***Creating/Updating Views `n"
$fileList = Get-ChildItem -Path .\views -Recurse
Foreach ($file in $fileList){
Write-Verbose $file.FullName
Invoke-Sqlcmd -ServerInstance $instance -Database $DatabaseName -InputFile $file.FullName -QueryTimeout 300
}
#Then scalar functions
Write-Verbose "`n ***Creating/Updating Scalar Functions `n"
$fileList = Get-ChildItem -Path .\functions-scalar -Recurse
Expand Down Expand Up @@ -104,6 +111,13 @@ foreach($instance in $InstanceName) {
Write-Verbose $file.FullName
Invoke-Sqlcmd -ServerInstance $instance -Database $DatabaseName -InputFile $file.FullName
}
## That Erik. He's such a Darling.
Write-Verbose "`n ***Creating/Updating Darling's Dandy Data Troubleshooting scripts `n"
$fileList = Get-ChildItem -Path .\oss\darlingdata -Recurse -Filter *.sql
Foreach ($file in $fileList){
Write-Verbose $file.FullName
Invoke-Sqlcmd -ServerInstance $instance -Database $DatabaseName -InputFile $file.FullName
}
}


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Some of this code (including the installer!) assumes that the First Responder Ki
### Open Source Projects License information:
* The First Responders Kit is distributed under the [MIT License](https://github.com/BrentOzarULTD/SQL-Server-First-Responder-Kit/blob/master/LICENSE.md).
* Ola Hallengren's SQL Server Maintenance Solution is distributed under the [MIT License](https://ola.hallengren.com/license.html).
* sp_WhoIsActive is distributed under the [GNU GPL v3](https://github.com/amachanic/sp_whoisactive/blob/master/LICENSE).
* sp_WhoIsActive is distributed under the [GNU GPL v3](https://github.com/amachanic/sp_whoisactive/blob/master/LICENSE).
* The Darling Data SQL Server Troubleshooting Scripts are distributed under the [MIT License](https://github.com/erikdarlingdata/DarlingData/blob/master/LICENSE.md).
15 changes: 7 additions & 8 deletions functions-scalar/dbo.EmailCss_Get.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ MODIFICATIONS:
*************************************************************************************************/
BEGIN
DECLARE @Style nvarchar(max),
--Use variables for font-family & colors
--Makes it easier to update them later
@FontFamily nvarchar(200) = '''Segoe UI'',''Arial'',''Helvetica''',
@ColorBoldText nvarchar(7) = '#032E57',
@ColorAlertText nvarchar(7) = '#DC080A',
@ColorBackground nvarchar(7) = '#D0CAC4',
@ColorBackground2 nvarchar(7) = '#E4F1FE',
@ColorBackgroundAlert nvarchar(7) = '#FEF1E4';
--Get color hex values from config table
@FontFamily nvarchar(200) = '''Segoe UI'',''Arial'',''Helvetica''',
@ColorBoldText nvarchar(7) = (SELECT UnicodeValue FROM dbo.Config WHERE ConfigCode = 'EMAILBOLDCOLOR'),
@ColorAlertText nvarchar(7) = (SELECT UnicodeValue FROM dbo.Config WHERE ConfigCode = 'EMAILALERTCOLOR'),
@ColorBackground nvarchar(7) = (SELECT UnicodeValue FROM dbo.Config WHERE ConfigCode = 'EMAILBGCOLOR'),
@ColorBackground2 nvarchar(7) = (SELECT UnicodeValue FROM dbo.Config WHERE ConfigCode = 'EMAILBGCOLOR2'),
@ColorBackgroundAlert nvarchar(7) = (SELECT UnicodeValue FROM dbo.Config WHERE ConfigCode = 'EMAILALRTBGCOLOR');


SET @Style = N'<style>
Expand Down
56 changes: 56 additions & 0 deletions functions-tvfs/dbo.Convert_LSNFromHexToDecimal.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
IF NOT EXISTS (SELECT * FROM sys.objects WHERE type = 'IF' AND object_id = object_id('dbo.Convert_LSNFromHexToDecimal'))
EXEC ('CREATE FUNCTION dbo.Convert_LSNFromHexToDecimal() RETURNS TABLE AS RETURN SELECT Result = ''This is a stub'';' )
GO


ALTER FUNCTION dbo.Convert_LSNFromHexToDecimal (@LSN varchar(22))
RETURNS TABLE
/*************************************************************************************************
AUTHOR: Andy Mallon
CREATED: 20190401
LSN is sometimes represented in hex (ie, from DBCC PAGE, fn_dblog(), sys.dm_db_page_info)
Hex LSNs are represented in the format '0000001e:00000038:0001'
Decimal LSNs are in the format 30000000005600001
PARAMETERS:
@LSN - Text string of the hex version of the LSN
In the format '0000001e:00000038:0001'
EXAMPLES:
* SELECT * FROM dbo.Convert_LSNFromHexToDecimal(0000001e:00000038:0001')
**************************************************************************************************
MODIFICATIONS:
20190401 -
**************************************************************************************************
This code is licensed as part of Andy Mallon's DBA Database.
https://github.com/amtwo/dba-database/blob/master/LICENSE
©2014-2020 ● Andy Mallon ● am2.co
*************************************************************************************************/

-- Split LSN into segments at colon
-- Convert to binary style 1 -> int
-- Add padded 0's to 2nd and 3rd string
-- Concatenate those strings & convert back to int

RETURN
--First chunk
SELECT LSN = CONVERT(decimal(25),
CONVERT(varchar(10),
CONVERT(int,
CONVERT(varbinary, '0x' + RIGHT(REPLICATE('0', 8) + LEFT(@LSN, 8), 8), 1)
)
)
--Second chunk
+ RIGHT(REPLICATE('0', 10) + CONVERT(varchar(10),
CONVERT(int,
CONVERT(varbinary, '0x' + RIGHT(REPLICATE('0', 8) + SUBSTRING(@LSN, 10, 8), 8), 1)
)
),
10)
--Third chunk
+ RIGHT(REPLICATE('0', 5) + CONVERT(varchar(5),
CONVERT(int,
CONVERT(varbinary, '0x' + RIGHT(REPLICATE('0', 8) + RIGHT(@LSN, 4), 8), 1)
)
),
5)
);
GO
6 changes: 3 additions & 3 deletions stored-procedures/dbo.Alert_Blocking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ BEGIN
--now get the object name
SET @WaitResource = SUBSTRING(@WaitResource,CHARINDEX(':',@WaitResource)+1,256);
SELECT @Sql = 'SELECT @ObjectName = SCHEMA_NAME(o.schema_id) + ''.'' + o.name, @IndexName = i.name ' +
'FROM [' + @DbName + '].sys.partitions p ' +
'JOIN [' + @DbName + '].sys.objects o ON p.OBJECT_ID = o.OBJECT_ID ' +
'JOIN [' + @DbName + '].sys.indexes i ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id ' +
'FROM ' + QUOTENAME(@DbName) + '.sys.partitions p ' +
'JOIN ' + QUOTENAME(@DbName) + '.sys.objects o ON p.OBJECT_ID = o.OBJECT_ID ' +
'JOIN ' + QUOTENAME(@DbName) + '.sys.indexes i ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id ' +
'WHERE p.hobt_id = SUBSTRING(@WaitResource,0,CHARINDEX('' '',@WaitResource))'
EXEC sp_executesql @sql,N'@WaitResource nvarchar(256),@ObjectName nvarchar(256) OUT,@IndexName nvarchar(256) OUT',
@WaitResource = @WaitResource, @ObjectName = @ObjectName OUT, @IndexName = @IndexName OUT
Expand Down
6 changes: 3 additions & 3 deletions stored-procedures/dbo.Check_Blocking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ BEGIN
--now get the object name
SET @WaitResource = SUBSTRING(@WaitResource,CHARINDEX(':',@WaitResource)+1,256);
SELECT @Sql = 'SELECT @ObjectName = SCHEMA_NAME(o.schema_id) + ''.'' + o.name, @IndexName = i.name ' +
'FROM [' + @DbName + '].sys.partitions p ' +
'JOIN [' + @DbName + '].sys.objects o ON p.OBJECT_ID = o.OBJECT_ID ' +
'JOIN [' + @DbName + '].sys.indexes i ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id ' +
'FROM ' + QUOTENAME(@DbName) + '.sys.partitions p ' +
'JOIN ' + QUOTENAME(@DbName) + '.sys.objects o ON p.OBJECT_ID = o.OBJECT_ID ' +
'JOIN ' + QUOTENAME(@DbName) + '.sys.indexes i ON p.OBJECT_ID = i.OBJECT_ID AND p.index_id = i.index_id ' +
'WHERE p.hobt_id = SUBSTRING(@WaitResource,0,CHARINDEX('' '',@WaitResource))'
EXEC sp_executesql @sql,N'@WaitResource nvarchar(256),@ObjectName nvarchar(256) OUT,@IndexName nvarchar(256) OUT',
@WaitResource = @WaitResource, @ObjectName = @ObjectName OUT, @IndexName = @IndexName OUT
Expand Down
12 changes: 6 additions & 6 deletions stored-procedures/dbo.Check_FileSize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ END
-- sys.sysfiles will show the *current* file size
-- Using sys.sysfiles has the right current file size in all cases.

EXEC sp_foreachdb
INSERT #FileSizeInfo (ServerName, DbName, FileSizeMB, SpaceUsedMB, GrowthAmount, LogicalFileName, PhysicalFileName, FileType, FreeSpaceMB, FreeSpacePct)
EXEC dbo.sp_ineachdb
@suppress_quotename = 1,
@state_desc = 'ONLINE',
@name_pattern = @DbName,
@command = 'USE [?]
INSERT #FileSizeInfo (ServerName, DbName, FileSizeMB, SpaceUsedMB, GrowthAmount, LogicalFileName, PhysicalFileName, FileType, FreeSpaceMB, FreeSpacePct)
SELECT @@servername as ServerName, ''?'' AS DatabaseName,
@command = '
SELECT @@servername as ServerName, db_name() AS DatabaseName,
CAST(f.size/128.0 AS decimal(20,2)) AS FileSize,
CASE
WHEN mf.type_desc = ''FILESTREAM'' THEN CAST(f.size/128.0 AS decimal(20,2))
Expand All @@ -104,7 +104,7 @@ EXEC sp_foreachdb
CAST(100 * (CAST (((f.size/128.0 -CAST(FILEPROPERTY(mf.name,
''SpaceUsed'' ) AS int)/128.0)/(f.size/128.0)) AS decimal(4,2))) AS varchar(8)) + ''%'' AS FreeSpacePct
FROM sys.master_files mf
JOIN [?].sys.database_files f ON f.file_id = mf.file_id AND mf.database_id = db_id(''?'')
JOIN sys.database_files f ON f.file_id = mf.file_id AND mf.database_id = db_id();
' ;


Expand All @@ -124,7 +124,7 @@ SET @sql = @sql + N' ORDER BY ' + @OrderBy;

PRINT @sql;

EXEC sp_executesql @sql;
EXEC sys.sp_executesql @sql;

GO

Expand Down
17 changes: 6 additions & 11 deletions stored-procedures/dbo.Check_LogVLF.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ PARAMETERS
number of VLFs, in case you don't care about those.
EXAMPLES:
**************************************************************************************************
MODIFICATIONS:
20150107 -
**************************************************************************************************
This code is licensed as part of Andy Mallon's DBA Database.
https://github.com/amtwo/dba-database/blob/master/LICENSE
Expand Down Expand Up @@ -49,14 +47,14 @@ CREATE TABLE #LogInfo
create_lsn numeric(25,0) );


--INSERT INTO #Results (DbName, LogFileName, PhysicalName, Growth)
EXEC sp_foreachdb @suppress_quotename = 1, @command = 'INSERT INTO #Results (DbName, LogFileName, PhysicalName, Growth)
SELECT ''?'' , name, physical_name,
INSERT INTO #Results (DbName, LogFileName, PhysicalName, Growth)
EXEC dbo.sp_ineachdb @suppress_quotename = 1, @command = '
SELECT db_name() , name, physical_name,
CASE WHEN growth = 0 THEN ''fixed'' ELSE
CASE WHEN is_percent_growth = 0 THEN CONVERT(varchar(10), (growth/128)) + '' MB''
WHEN is_percent_growth = 1 THEN CONVERT(varchar(10), growth) +'' PERCENT'' END
END AS [growth]
FROM [?].sys.database_files
FROM sys.database_files
WHERE type_desc = ''LOG''; ';


Expand All @@ -74,7 +72,7 @@ WHILE @@FETCH_STATUS=0
ELSE
SET @sql='Insert #LogInfo(RecoveryUnitID, fileid, file_size, start_offset, FSeqNo, [status], parity, create_lsn) Exec(''DBCC loginfo ('+QUOTENAME(@dbname)+')'')';
PRINT @sql;
EXEC (@sql);
EXEC sys.sp_executesql @stmt = @sql;
UPDATE #Results SET vlf=(SELECT COUNT(*) FROM #LogInfo) WHERE dbname=@DbName;
FETCH Next FROM db_cur INTO @DbName;
END;
Expand All @@ -88,9 +86,6 @@ WHERE vlf >= @Threshold
ORDER BY VLF DESC;





GO


Empty file.
8 changes: 4 additions & 4 deletions stored-procedures/dbo.Repl_AddAllTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ CREATE TABLE #article (

--Get all unpublished tables that have a PK
SET @sql = N'SELECT t.name
FROM [' + @PubDbName + '].sys.objects t
JOIN [' + @PubDbName + '].sys.objects pk ON pk.parent_object_id = t.object_id
FROM ' + QUOTENAME(@PubDbName) + '.sys.objects t
JOIN ' + QUOTENAME(@PubDbName) + '.sys.objects pk ON pk.parent_object_id = t.object_id
WHERE t.is_ms_shipped = 0
AND t.is_published = 0
AND t.name NOT IN (' + COALESCE(@ExcludeTables,'''''') + ')
AND t.type = ''U'';';

INSERT INTO #article
EXEC sp_executesql @sql;
EXEC sys.sp_executesql @sql;

--Call Repl_AddArticle in a loop for every table in #article
--Debug mode works by passing parameter through to Repl_AddArticle to print statement
Expand All @@ -69,7 +69,7 @@ END;
CLOSE article_cur;
DEALLOCATE article_cur;

DROP TABLE #article
DROP TABLE #article;
GO


Loading

0 comments on commit 57f0016

Please sign in to comment.