Database Reference
In-Depth Information
The easiest way is to just ask the database a simple query, such as the following:
SELECT pg_database_size(current_database());
However, this is limited to only the current database. If you want to find out the size
of all databases together, then you'll need a query such as the following:
SELECT sum(pg_database_size(datname)) from pg_database;
How it works...
The database server knows which tables it has loaded. It also knows how to calculate the size
of each table, so the pg_database_size() function just goes and looks at the filesizes.
How much disk space does a table use?
How big is a table? What is the total of all the parts of a table?
How to do it...
We can find out the size of a table using the following query:
postgres=# select pg_relation_size('accounts');
pg_relation_size
------------------
0
(1 row)
We can also find out the total size of a table including indexes and other related space
using the following query:
postgres=# select pg_total_relation_size('accounts');
pg_total_relation_size
------------------------
0
(1 row)
or we can also use a psql command as follows:
postgres=# \dt+ accounts
List of relations Schema | Name
| Type | Owner | Size | Description ------------+---------------
--------+--------+---------+----------+---------------- public |
pgbench_accounts | table | sriggs | 13 MB |
(1 row)
 
Search WWH ::




Custom Search