Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres DB Size Command

What is the command to find the size of all the databases?

I am able to find the size of a specific database by using following command:

select pg_database_size('databaseName'); 
like image 729
Beautiful Mind Avatar asked Sep 20 '13 00:09

Beautiful Mind


People also ask

How do I find the index size in PostgreSQL?

PostgreSQL index size To get total size of all indexes attached to a table, you use the pg_indexes_size() function. The pg_indexes_size() function accepts the OID or table name as the argument and returns the total disk space used by all indexes attached of that table.

What is Pg_size_pretty?

pg_size_pretty(numeric) text. Converts a size in bytes expressed as a numeric value into a human-readable format with size units. pg_table_size(regclass)

How do I view PostgreSQL databases?

Use \l or \l+ in psql to show all databases in the current PostgreSQL server. Use the SELECT statement to query data from the pg_database to get all databases.

What is page size in PostgreSQL?

PostgreSQL uses a fixed page size (commonly 8 kB), and does not allow tuples to span multiple pages.


2 Answers

You can enter the following psql meta-command to get some details about a specified database, including its size:

\l+ <database_name> 

And to get sizes of all databases (that you can connect to):

\l+ 
like image 176
Ashish Avatar answered Sep 23 '22 14:09

Ashish


You can get the names of all the databases that you can connect to from the "pg_datbase" system table. Just apply the function to the names, as below.

select t1.datname AS db_name,          pg_size_pretty(pg_database_size(t1.datname)) as db_size from pg_database t1 order by pg_database_size(t1.datname) desc; 

If you intend the output to be consumed by a machine instead of a human, you can cut the pg_size_pretty() function.

like image 23
Mike Sherrill 'Cat Recall' Avatar answered Sep 20 '22 14:09

Mike Sherrill 'Cat Recall'