There is a PostgreSQL base base
, user postgres
. How to get the size of the database in one command, without using scripts?
Answer 1, authority 100%
Enter the interactive terminal:
$ sudo -u postgres psql
Run request:
# select pg_database_size ('base');
Answer 2, authority 94%
In human form, the size of the base will be shown by the pg_size_pretty wrapper
SELECT pg_size_pretty (pg_database_size ('sample_db'));
pg_size_pretty
----------------
36 GB
In the same way, you can see the size of the table (with indexes)
SELECT pg_size_pretty (pg_total_relation_size ('table'));
pg_size_pretty
----------------
6341 MB
If you need without indexes, then the request is different:
# SELECT pg_size_pretty (pg_relation_size ('table'));
pg_size_pretty
----------------
1341 MB
Answer 3
Size of all databases line by line:
select datname, pg_size_pretty (pg_database_size (datname))
from pg_database
The total size of all databases with one value:
select pg_size_pretty (sum (pg_database_size (datname)))
from pg_database