DEV Community

Cover image for SQL Command to list databases along with their storage consumption
toufiqAT
toufiqAT

Posted on

SQL Command to list databases along with their storage consumption

To list databases along with their storage consumption, here are how to do it for popular databases

PostgreSQL

SELECT
  datname AS database_name,
  pg_size_pretty(pg_database_size(datname)) AS size
FROM
  pg_database
ORDER BY
  pg_database_size(datname) DESC;
Enter fullscreen mode Exit fullscreen mode

MySQL / MariaDB

SELECT 
  table_schema AS database_name,
  ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS size_in_mb
FROM 
  information_schema.tables
GROUP BY 
  table_schema
ORDER BY 
  size_in_mb DESC;
Enter fullscreen mode Exit fullscreen mode

Clickhouse

SELECT
  database,
  formatReadableSize(sum(bytes_on_disk)) AS total_size
FROM
  system.parts
GROUP BY
  database
ORDER BY
  sum(bytes_on_disk) DESC;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)