Skip to content

Instantly share code, notes, and snippets.

Avatar

nanoDBA nanoDBA

View GitHub Profile
@nanoDBA
nanoDBA / Sequential_Restores.ps1
Created Apr 30, 2019
Demo - PowerShell + DevOps Global Summit 2019 - Sequential Restores
View Sequential_Restores.ps1
# How will the backup headers be scanned? SQL Server and Backup Path
$BkParamHash = @{
SqlInstance = "localhost"
Path = "D:\Share01\Demo", "D:\Share02\Demo"
}
$BackupMetaData = Get-DbaBackupInformation @BkParamHash -Verbose
# Let's restore 11 databases
$DbSuffixRange = 500..510
@nanoDBA
nanoDBA / Practical PowerShell for Busy DBAs.ps1
Created Apr 30, 2019
Intro to PowerShell and dbatools for SQL Server DBAs (originally presented in August 2018 using the ISE)
View Practical PowerShell for Busy DBAs.ps1
#requires -version 5.0
#requires runasadministrator
#region overview
<#
'Practical PowerShell for The Busy DBA' – this will be hands-on (lab + presentation)
- Basic overview of PowerShell and getting started (WMF 5.1 and other versions: prereqs, cmdlets,
transcription, console navigation, and getting quick help/examples)
- Installing Modules with PowerShell 5.0 and up
@nanoDBA
nanoDBA / Get-SPIDs_last_batch.sql
Created May 31, 2019
Last_Batch timestamp - From "How to detect SqlServer connection leaks in a ASP.net applications?"
View Get-SPIDs_last_batch.sql
--Get-SPIDs_last_batch.sql
-- https://stackoverflow.com/questions/212596/how-to-detect-sqlserver-connection-leaks-in-a-asp-net-applications/12428235#12428235
SELECT S.spid, S.login_time, S.last_batch, S.status, S.hostname, S.program_name, S.cmd, S.loginame,
last_sql = ( select text from sys.dm_exec_sql_text(S.sql_handle) )
, database_name = DB_NAME(dbid)
FROM sys.sysprocesses S
INNER JOIN sys.dm_exec_sessions sx
on sx.session_id = S.spid
and sx.is_user_process = 1
View fix page verification by setting it to checksum in databases.sql
--https://www.brentozar.com/blitz/page-verification/
--An alternative to sp_msforeachdb
--https://johnmccormack.it/2015/12/an-alternative-to-sp_msforeachdb/
SET NOCOUNT ON;
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp;
SELECT name, 0 AS completed
INTO #tmp
FROM sys.databases AS s
WHERE s.page_verify_option_desc <> 'CHECKSUM'
You can’t perform that action at this time.