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:

$ python manage.py dbshell

Then execute these SQL commands:

> /* 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

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.