DBA SQL Scripts

Working as a DBA (Database Administrator) for many years I wrote a large amount of SQL scripts. Here are the most intresting and recent snippets [NdA I wrote a similar page more than ten years ago].

The DBAs' job is similar to the Doctors' one... they both must analyze the data to make the diagnosis and choose the right treatment. Often the DBA uses sophisticated tools that allow quick diagnosis like an electrocardiogram or a CT scan. But for some complex or strange cases there isn't any tool and you need to collect and analyze data by creating a new program. In the majority of cases they are simple queries such as an oximeter, but they are very useful!

PostgreSQL/Oracle/MySQL DBA Cheat Sheet

PostgreSQL, Oracle, and MySQL relational database are quite similar from the application developer point of view while they are very different for a DBA.

The following table contains some useful query for DBAs on both databases:
  [Click on the [...] button to see the full query text and on the 📋 button to copy the query code]

Copied!
Action PostgreSQL Oracle MySQL
Sessions
PostgreSQL
Oracle
MySQL
Active Sessions (cond.)
PostgreSQL
Additional condition for PostgreSQL Sessions
Oracle
Additional condition for Oracle Sessions
MySQL
Additional condition for MySQL Sessions
Locks
PostgreSQL
Oracle
MySQL
Space Usage
PostgreSQL
Oracle
MySQL
Biggest Objects (TOP5)
PostgreSQL
Oracle
MySQL
Heaviest Statements (TOP5)
PostgreSQL
Oracle
MySQL
Buffer Cache Hit
PostgreSQL
Oracle
MySQL
Replica
PostgreSQL
Oracle
MySQL
Database Parameters
PostgreSQL
Oracle
MySQL

Note

The query presented in this page refers to the following database versions: PostgreSQL 18, Oracle 26ai, MySQL 8.4.

Other useful queries for PostgreSQL, MySQL, and Oracle can be found in the GitHub db2txt script collection.


Title: New DBA SQL Scripts
Level: Advanced (3/5)
Date: 1st April 2026
Version: 1.0.0 - 1st April 2026
Author: mail [AT] meo.bogliolo.name