This tutorial will help you to determine database size and table size in the PostgreSQL server.
First login to your server using the command line and connect to the PostgreSQL server. Now you can use the following commands to determine the sizes of databases and tables in PostgreSQL.
1. Check PostgreSQL Database Size (Query)
Use the following commands to determine PostgreSQL database size using a query. First, open a shell and connect to the Postgres terminal.
sudo -u postgres psql
Then use inbuild function pg_database_size() to find database size in PostgreSQL server.
postgres=#SELECT pg_database_size(' mydb');
You can also use
pg_size_pretty() function along with above to determine database size in human readable format like KB, MB, and GB etc.
postgres=#SELECT pg_size_pretty(pg_database_size(' mydb'));
2. Check PostgreSQL Database Size with pgAdmin
The pgAdmin users can also determine the size from the interface.
First login to the pgAdmin3 interface. Select your database and open statics tab. Here you can find the Size of your database as shown in below image:
3. How to Find Table Size in PostgreSQL
Connect to the target database first with the following command:
Now calculate the table size in Postgres server using
pg_total_relation_size() inbuilt function with human readable format.
mydb=#SELECT pg_size_pretty(pg_total_relation_size(' employee'));
This tutorial helps you to find database size in the PostgreSQL server. Also, provide you details to calculate table size in a database.
Good Work.Please keep it up.