Postgresql how to get database size

  • Last updated: Nov 3, 2023
  • Views: 290
  • Author: Admin
Postgresql how to get database size

Colleagues hello to all.

In today's short article, I'll show you a couple of queries that show the size of all databases or a single database in Postgresql.

 

The first query shows the size of each database.

psql> SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database;

postgresql_database_size

 

The second query shows the size of the database, the name we specify.

psql> SELECT pg_size_pretty(pg_database_size('demo'));

postgresql_database_size


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

PostgreSQL - pg_dump creating backup with bzip2 compression

PostgreSQL - pg_dump creating backup with bzip2 compression

PostgreSQL - how to reset postgres password

PostgreSQL - how to reset postgres password

Download and install Postgresql 14 on Linux CentOS/RHEL 8/7 TAR

Download and install Postgresql 14 on Linux CentOS/RHEL 8/7 TAR