Skip to content

Instantly share code, notes, and snippets.

@cmlenz
Forked from thomasbilk/database_size.sql
Created March 7, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmlenz/1992369 to your computer and use it in GitHub Desktop.
Save cmlenz/1992369 to your computer and use it in GitHub Desktop.
Database Sizes
-- PostgreSql
SELECT
pg_database.datname AS "Database Name",
pg_database_size(pg_database.datname) / 1024.0 / 1024.0 AS "Database Size (MB)"
FROM pg_database;
-- MySql
SELECT
table_schema "Database Name",
sum( data_length + index_length ) / 1024 / 1024 "Database Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;
-- MSSQL (current database only)
EXEC sp_spaceused
-- WARNING: returns 2(!) result sets, and the size values
-- are strings (!!) such as "517.13 MB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment