Skip to main content

DBA Scripts

Reusable operational scripts. Each entry includes risk level, required permissions, and platform compatibility.

Test before production use. Review permissions, assumptions, workload impact, and rollback requirements. No script should be executed in production without change-control approval where applicable.

Identifies exact duplicate indexes on the same table — indexes with identical key column lists in the same order — so that redundant indexes can be safely dropped to reduce write overhead and storage in MySQL and MariaDB.

MySQL8.0, 8.4Index Maintenance

Identifies exact duplicate indexes on the same table — indexes with identical key column lists in the same order — so that redundant indexes can be safely dropped to reduce write overhead and segment storage.

Oracle19c, 21c, 23aiIndex Maintenance

Estimates the size of a proposed B-tree index before creation — calculates the per-entry byte footprint from key column type widths using USER_TAB_COLUMNS and average column lengths, then projects total size against the current row count, block size, and PCTFREE.

Oracle19c, 21c, 23aiCapacity Planning

Renders the current PostgreSQL blocking chain as an indented tree using a recursive CTE — head blockers at the root, blocked sessions as branches — with lock type, relation, wait duration, and query text per session.

PostgreSQL13, 14, 15, 16, 17, 18Diagnostics

Identifies exact duplicate indexes on the same table — indexes with identical key column lists and identical INCLUDE column lists — so that redundant indexes can be safely dropped to reduce write amplification and storage.

PostgreSQL13, 14, 15, 16, 17, 18Index Maintenance

Estimates the size of a proposed B-tree index before creation — calculates the per-tuple byte footprint from key column type widths, then projects total size against the current row count and fill factor.

PostgreSQL13, 14, 15, 16, 17, 18Capacity Planning

Renders the current blocking chain as an indented tree — head blockers at the root, blocked sessions as branches — showing the SQL text of each session for rapid identification of the source of contention.

SQL Server2012, 2016, 2017, 2019, 2022Diagnostics

Identifies exact duplicate indexes on the same table — indexes with identical key column lists and identical INCLUDE column lists — so that redundant indexes can be safely dropped to reduce write overhead and storage.

SQL Server2017, 2019, 2022Index Maintenance

Estimates the size of a proposed nonclustered index before creation — calculates the per-row byte footprint from the key and INCLUDE column definitions, then projects total size against the current row count and fill factor.

SQL Server2012, 2016, 2017, 2019, 2022Capacity Planning

Combines Query Store runtime statistics and wait category data into a single ranked view — execution counts, duration metrics, total wait time, and a per-category wait breakdown per plan — for identifying the costliest queries in a time window.

SQL Server2017, 2019, 2022Performance Analysis

Identifies which queries are accumulating the most wait time across key wait categories in a defined time window — useful for pinpointing the source of contention during an incident or after a regression.

SQL Server2017, 2019, 2022Performance Analysis

Breaks down wait time by category for a specific query over a defined time window using Query Store — useful for diagnosing whether a regression is caused by I/O, CPU, locking, memory, or another resource.

SQL Server2016, 2017, 2019, 2022Performance Analysis

RMAN commands to verify Oracle backups are complete, restorable, and within the defined retention policy.

Oracle12c, 19c, 21c, 23aiHealth Check

PowerShell script to collect SQL Server instance inventory — version, edition, databases, and service accounts — across multiple hosts.

SQL Server2016, 2017, 2019, 2022Inventory

Review SQL Server index usage statistics to identify unused, duplicate, and missing indexes using DMVs.

SQL Server2016, 2017, 2019, 2022Diagnostic

Monitor PostgreSQL WAL generation rate, checkpoint frequency, and bgwriter activity to identify I/O configuration and checkpoint tuning issues.

PostgreSQL13, 14, 15, 16, 17Diagnostic

Diagnose parallel query issues in Oracle — active parallel sessions, degree of parallelism, parallel query waits, and PQ slave activity.

Oracle12c, 19c, 21c, 23aiDiagnostic

Identify unused, redundant, and missing indexes in PostgreSQL using pg_stat_user_indexes and pg_stat_user_tables.

PostgreSQL13, 14, 15, 16, 17Diagnostic

Query to identify blocking lock chains in PostgreSQL — which session is blocking, what it holds, and what the blocked sessions are waiting for.

PostgreSQL13, 14, 15, 16, 17Diagnostic

SQL*Plus script to verify Oracle Data Guard physical standby state — apply status, transport and apply lag, archive gap detection, and protection mode.

Oracle12c, 19c, 21c, 23aiHealth Check

Health check script for SQL Server Always On Availability Groups — synchronisation state, replica status, log send and redo queue sizes, and listener configuration.

SQL Server2016, 2017, 2019, 2022Health Check

A comprehensive SQL Server instance health check covering waits, blocking, missing indexes, disk space, and backup status.

SQL Server2016, 2017, 2019, 2022Health Check