Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Last active May 22, 2026 14:56
Show Gist options
  • Select an option

  • Save vyspiansky/003e80f8615506b311508458c9037d1d to your computer and use it in GitHub Desktop.

Select an option

Save vyspiansky/003e80f8615506b311508458c9037d1d to your computer and use it in GitHub Desktop.
MariaDB performance profiling

Enable query log temporarily

Inside the MySQL prompt:

SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/tmp/mariadb_general.log';

Or use one-liner from terminal

mysql -u root -e "SET GLOBAL general_log = 'ON'; SET GLOBAL general_log_file = '/tmp/mariadb_general.log';"

Turn the log off afterwards:

SET GLOBAL general_log = 'OFF';

Enable a slow query log

Check these settings in my.cnf (a MariaDB configuration file):

iniinnodb_buffer_pool_size = 512M # Should be ~70% of available RAM
query_cache_type = 1
query_cache_size = 64M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1 # Log queries taking >1s

It'll tell you exactly which queries need attention.

Check an average row size

SELECT
  table_name,
  table_rows,
  avg_row_length,
  ROUND((data_length + index_length) / 1024 / 1024, 2) AS total_mb
FROM information_schema.tables
WHERE table_name = 'your_table';

Check a table size

SELECT
  ROUND((data_length + index_length) / 1024 / 1024, 2) AS size_mb
FROM information_schema.tables
WHERE table_name = 'your_table';

Check field(s) content size:

SELECT
  AVG(LENGTH(your_field)) AS avg_your_field,
  MAX(LENGTH(your_field)) AS max_your_field
FROM your_table;

Check a total database size

SELECT
  ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_gb
FROM information_schema.tables
WHERE table_schema = DATABASE();

Check top largest tables

SELECT
  table_name,
  ROUND((data_length + index_length) / 1024 / 1024 / 1024, 2) AS size_gb
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY size_gb DESC
LIMIT 10;

See also Top 10 largest tables in a MySQL database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment