Christopher Tyler

Get Disk Size for Each Database

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

To get the size in megabytes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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)

<< Previous Post

|

Next Post >>

#Til #Taop #Postgresql #Psql #The Art of PostgreSQL #Pg_database