Skip to content

Instantly share code, notes, and snippets.

View nanoDBA's full-sized avatar

nanoDBA nanoDBA

View GitHub Profile
@nanoDBA
nanoDBA / Move-TempDb.ps1
Created September 4, 2025 20:42
Safely migrate SQL Server TempDb files to a new location, following best practices for file count, permissions, and logging. Downtime required; use with caution in production.
<#
.SYNOPSIS
Moves SQL Server TempDb files to a new location with best practices.
.DESCRIPTION
This script safely relocates SQL Server TempDb files to a specified path.
It handles:
- File count optimization based on CPU cores (Best Practices)
- Preserving or standardizing filenames
- Robust directory creation and permission setup (with `xp_cmdshell` fallback)
@nanoDBA
nanoDBA / Set-EC2VolumeAttribute.ps1
Last active August 20, 2025 22:30
Safely modifies EBS volumes with validation and dry-run support
# ------------------------------------------------------------------------------
# File: Set-EC2VolumeAttribute.ps1
# Description: Bulk EBS volume modification script with enterprise-grade safety features
# Purpose: The Swiss Army knife of EBS volume management! This script lets you
# transform multiple AWS EBS volumes in one go with surgical precision:
# - Convert gp2 to gp3 while preserving performance (because storage
# shouldn't be boring) 📈
# - Scale IOPS and throughput without downtime (your users will thank you) ⚡
# - Bulk resize operations with safety guards (no more "oops" moments) 🛡️
# - Intelligent discovery and filtering (find those volumes hiding in the
@nanoDBA
nanoDBA / Get-EC2VolumesAttached.ps1
Created August 7, 2025 17:31
This function retrieves the volumes attached to the specified EC2 instances in the specified region. It returns a list of volume details including the instance ID, instance name, instance type, volume ID, device name, state, availability zone, volume type, IOPS, throughput, and size.
<#
.SYNOPSIS
Get the volumes attached to the EC2 instances.
.DESCRIPTION
This function retrieves the volumes attached to the specified EC2 instances in the
specified region. It returns a list of volume details including the instance ID,
instance name, instance type, volume ID, device name, state, availability zone,
volume type, IOPS, throughput, and size.
@nanoDBA
nanoDBA / sp_SDS.sql
Created June 20, 2025 16:47
🚀 Souped-up space reporting stored procedure (originally by Richard Ding) that details your database sizes
/*
File: sp_SDS.sql
Description: 🚀 A souped-up space-reporting stored procedure that tells you everything about your database sizes.
Purpose: This procedure provides detailed reports on database space usage, from high-level summaries down to
individual file details. It's designed for DBAs who need to quickly diagnose space issues, monitor
growth, and generate reports for capacity planning. It includes advanced filtering by filegroup,
logical file name, and physical path, with flexible output formats for both interactive use and Nagios
monitoring. Think of it as sp_spaceused on steroids. 💪
Created: 2008-04-08
Author: Richard Ding
@nanoDBA
nanoDBA / Improved-Fill-TestLogVolume.sql
Created May 22, 2025 14:57
🚀 Rapidly fills a SQL Server test database log file to simulate disk full and alerting scenarios. Useful for testing error handling, monitoring, and DBA/ops automation. 😎
/*
| File: Improved-Fill-TestLogVolume.sql
| Description: 🚀 Rapidly fills a SQL Server test database log file to simulate
| disk full and alerting scenarios. Useful for testing error
| handling, monitoring, and DBA/ops automation. 😎
| Purpose: Quickly consume log file space to test SQL Server's response to
| log growth, disk full, and alerting. Designed for use in
| dev/test environments only! Not for prod! ⚠️
| The script can optionally reserve a buffer of free space on the
| log drive, or attempt to fill the drive completely. See below.
@nanoDBA
nanoDBA / Get-DiskSpaceWithFreeGoal.ps1
Last active April 19, 2025 13:20
Checks disk space, shows extra space needed to meet target free %
<#
.SYNOPSIS
Retrieves disk space info from remote computers and computes the
extra free space needed to meet target free space percentages.
.DESCRIPTION
This function serves as a wrapper around the dbatools.io Get-DbaDiskSpace cmdlet,
extending its functionality with additional calculations.
It queries remote systems for disk space details, filters the output by specified
@nanoDBA
nanoDBA / monitor_active_sessions.sql
Created March 12, 2025 15:06
Dump sp_WhoIsActive to a table
-- ████████ FILE: monitor_active_sessions.sql ████████
-- 🎯 MISSION OBJECTIVE: Real-time monitoring of active SQL Server sessions.
-- - If the table **does not exist**, create it.
-- - If the table **exists**, append new data.
-- - If you need a **hard reset**, uncomment the DROP TABLE line.
--
-- 🔧 USAGE:
-- 🎮 Execute in SSMS or a SQL Agent job for continuous ops.
-- 🔬 Uncomment DROP TABLE if you want to refresh the dataset.
@nanoDBA
nanoDBA / Get-EC2VolumeModificationDetails.ps1
Created February 13, 2025 22:22
Retrieves AWS EC2 volume modification records (size, IOPS, volume type changes, etc) and appends the associated instance name. Uses AWS Tools for PowerShell
<#
.SYNOPSIS
Retrieves AWS EC2 volume modification records and useful metadata.
🚀 Because sometimes we need speedy volume modifications!
.DESCRIPTION
The Get-EC2VolumeModificationDetails function retrieves modification details
for a list of specified EC2 volumes such as size, IOPS, volume type changes,
etc. It uses AWS SDK for .NET to interact with AWS EC2 services.
🤖 This function fetches the modification details and the associated instance
@nanoDBA
nanoDBA / Get-RecommendedSqlCU.ps1
Last active November 21, 2024 13:57
Finds the recommended N-1 cumulative update for SQL Server based on patching strategy that avoids intermediate releases
<#
.SYNOPSIS
Finds the recommended N-1 cumulative update for SQL Server based on patching strategy that avoids intermediate releases
.DESCRIPTION
This script queries a Google Sheets document containing SQL Server cumulative update information
and determines the recommended N-1 cumulative update based on a patching strategy that avoids
intermediate releases (e.g., hotfixes, security updates) between cumulative updates.
The script outputs the recommended cumulative update, its release date, and a link to more details.
The patching strategy is defined as follows:
@nanoDBA
nanoDBA / ServiceBrokerLogNoiseReductionEndpoint.sql
Last active May 22, 2025 18:22
Creates SQL Server Service Broker endpoint on port 4022 to reduce noise in the SQL Server error log (ERRORLOG). Includes port availability checks, conditional creation, logging, and optional code to stop and drop endpoint if needed.
/*
| File: ServiceBrokerLogNoiseReductionEndpoint.sql
| Description: 🚦 Creates a Service Broker endpoint to reduce SQL Server log noise.
| Purpose: Sets up a dedicated endpoint for Service Broker on a user-chosen
| port (default 4022), with checks for port conflicts and robust
| logging. Useful for DBAs who want to keep error logs clean and
| avoid noisy Service Broker errors. Includes optional code to drop
| the endpoint. For test/dev use or advanced troubleshooting. 😎
| Created: 2024-05-21
| Modified: 2025-05-22