About Measuring the Size of PostgreSQL Database and its Tables

To check the size of a PostgreSQL database and its tables run the dbshell management command:

1
$ python manage.py dbshell

Then execute these SQL commands:

1
2
3
4
5
6
> /* Show the size of the 'djangotricks' database */
> SELECT pg_size_pretty(pg_database_size('djangotricks'));
> /* List out database tables */
> \dt
> /* Show the size of the 'tricks_trick' database table */
> SELECT pg_size_pretty(pg_total_relation_size('tricks_trick'));

Tips and Tricks Dev Ops Optimization Maintenance Django 4.2 Django 3.2 Django 2.2 PostgreSQL