Home›Practice›Health check

Health check

What would a database engineer look at first on my server?

Run one read-only script against your database, paste its output here, and get a report: connections, cache, the oldest open transaction, the biggest tables, dead rows, unused indexes, replication, the queries that take the most time, and the settings. It is the first hour of a database review, done by a script.

Step 1

Run the script

The scripts only read: SELECT statements and status commands, nothing that changes data or settings. Read them before you run them; they are short.

Engine

PostgreSQL 13 and later

Download health-pg.sql, then run:

psql -At -F'|' -X -d yourdb -f health-pg.sql > report.txt

Needs a role that can read the statistics views; the built-in pg_monitor role is enough. Run it in the database your application uses.

MySQL 8.0 and later

Download health-my.sql, then run:

mysql -B -N -u youruser -p < health-my.sql > report.txt

Needs SELECT on performance_schema, information_schema and sys, and PROCESS to see other sessions' transactions.

MongoDB 6.0 and later

Download health-mo.js, then run:

mongosh --quiet "mongodb://youruser@yourhost/admin" health-mo.js > report.txt

Needs the clusterMonitor role, or one that can run serverStatus, replSetGetStatus and $indexStats.

Step 2

Paste the output

Private by design. Everything runs in your browser. Nothing you paste is sent anywhere, saved, or seen by me. Still, remove host names, user names and anything sensitive before pasting if your company requires it.

After the report

What the report cannot tell you

Connected

Where this shows up

The same mechanism, old row versions, vacuum and long transactions, replication and failover, backups and restore, elsewhere on the site: in real incidents, in measurements, and in designs.

Part 2 of 4 · Practice · 9 pagesAll pages

Can I see it happen? Simulations, an index you build yourself, a real PostgreSQL in your browser, experiments run on real servers, and tools for your own database: a query coach, an EXPLAIN reader, a config checker and a health check.