Postgresql find total disk space used by a database
SELECT pg_database_size('geekdb')
or
SELECT pg_size_pretty(pg_database_size('geekdb'))
http://www.thegeekstuff.com/2009/05/15-advanced-postgresql-commands-with-examples/
postgresql list and order tables by size
select table_name, pg_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public'
order by 2
This shows you the size of all tables in the schema public
if you have multiple schemas, you might want to use:
select table_schema, table_name, pg_relation_size('"'||table_schema||'"."'||table_name||'"')
from information_schema.tables
order by 3
SQLFiddle example: http://sqlfiddle.com/#!15/13157/3
List of all object size functions in the manual.
Postgres Database size and Table size sum do not match up
The issue appears to be connected to the dirty shutdown.
The solution is posted on dba stackexchange: How to reclaim space taken by an index that partially built and was terminated by a power outage
Should you suffer the same issue, check it for solution.
How can i get the size of every db on my PostgreSQL server
Make use of system information functions:
https://www.postgresql.org/docs/current/functions-admin.html
For database sizes:
select datname, pg_size_pretty(pg_database_size(datname)) from pg_database ;
datname | pg_size_pretty
------------------------+----------------
my_test_db | 7865 kB
production | 64 MB
no_public_sch_template | 7857 kB
test | 11 MB
test_gz | 9681 kB
sch_test | 7857 kB
template0 | 7713 kB
task_manager | 9681 kB
template1 | 7865 kB
aquaculture | 15 MB
track_stocks | 9425 kB
track_stocks_test | 9529 kB
postgres | 8273 kB
From pg_database you can get the database name(datname) for building a script to iterate over for the tables.
Related Topics
Differencebetween a Hash Join and a Merge Join (Oracle Rdbms )
Index on Timestamp: Functions in Index Expression Must Be Marked as Immutable
Fetch a Record on Maximum Date of Every Month
Update Table with a Subquery Which Is Returning More Than One Row
Postgresql - Query from Bash Script as Database User 'Postgres'
Select Top N Rows for Each Group
Using the Web.Config to Set Up My SQL Database Connection String
Trying to Flatten Rows into Columns
Oracle Insert via Select from Multiple Tables Where One Table May Not Have a Row
How to Update in SQLite Using a Left Join to Select Candidate Rows
A Procedure to Reverse a String in Pl/Sql
Understanding the Differences Between Cube and Rollup
How to Use Explain Plan to Optimize Queries
What Does "Select Count(1) from Table_Name" on Any Database Tables Mean