Get Disk Size for Each Database

Get Disk Size for Each Database

March 10, 2023

I learned this from Dimitri’s The Art of PostgreSQL.

To get the size in megabytes:

postgres@f1db=# SELECT datname
 ,pg_database_size(datname) / (1024 * 1024) AS megabytes
FROM pg_database
ORDER BY megabytes DESC;

   datname   megabytes 
 ═══════════╪═══════════
  raw_data         531
  f1db              73
  chinook            9
  postgres           7
  template1          7
  template0          7
 (6 rows)