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;
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;
Clickhouse
SELECT
database,
formatReadableSize(sum(bytes_on_disk)) AS total_size
FROM
system.parts
GROUP BY
database
ORDER BY
sum(bytes_on_disk) DESC;
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)