brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mariadb-admin in relative mode shows what the server is doing right now

Mariadb
~/tips/tip-mariadb-admin-relative-status

mariadb-admin -u root -p extended-status --relative --sleep=10 \

Turns ever growing server counters into per interval numbers.

Server status counters only ever go up, so a figure like twelve million queries says little about this minute. mariadb-admin can show the differences instead.

Ask for the status repeatedly and in relative mode:

mariadb-admin -u root -p extended-status --relative --sleep=10 \
  | grep -E 'Questions|Slow_queries|Created_tmp_disk|Select_scan'

The first block holds the totals since startup. Every block after it shows how much each value changed during the last ten seconds, so a Questions of 500 means about fifty a second. Stop it with Ctrl+C, or add --count=6 to collect a minute and quit.

I like it for the question “is something hammering the database right now?”. Run it while you click around your application and watch which counters jump. A climbing count of temporary tables on disk or rows read without an index points to a query worth examining.

Gauges behave differently from counters. Something like Threads_connected is a current level, so its relative value is the change since the last sample and can be negative. Read those from a plain SHOW GLOBAL STATUS instead.

Your own monitoring connection adds a little to the numbers too, so on an idle server don’t be alarmed that it never reads exactly zero. And with -p the password prompt appears before the output starts; don’t put the password on the command line, where other users can see it in the process list.

Further reading: mariadb-admin documentation

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Mariadb tips ALTER TABLE t ADD COLUMN z INT INVISIBLE; CREATE SEQUENCE s START WITH 100 INCREMENT BY 10; CREATE OR REPLACE TABLE scratch ( mariadb --init-command="SET SESSION sql_mode='STRICT_ALL_TABLES'" mydb ALTER USER 'app'@'localhost' ACCOUNT LOCK; All Mariadb tips (15) All topics

Link