1 min read

Counting table row counts in PostgreSQL

An easy way to count the number of rows in a PostgreSQL table and sort by totals allowing you to find what's taking up space in your database.

Counting table row counts in PostgreSQL
Author
Isaac Bythewood Isaac Bythewood
2022-05-28

I sometimes find myself running into the problem of hunting down what is taking up a lot of rows in PostgreSQL due to service row restrictions. There is a choice of increasing my service plan but I sometimes find it unnecessary if I have a rogue app just adding a lot of data that can be purged. This happens a lot of logs and security apps tracking login attempts. To find the number of rows used in a PostgreSQL database and order it by count you can run this in psql.

If this runs correctly you should see a sorted list of tables with their row counts. From there you can create a script to purge the offending apps on a schedule if you don't need older data.


Related posts

Some posts in similar tags to this one.

Capturing screenshots with Chromium using Python
Capturing screenshots with Chromium using Python
Sometimes you need to take screenshots of the web and Chromium provides an easy way to do that.
Isaac Bythewood Isaac Bythewood
2022-08-06
Code formatting a Python project in 2022
Code formatting a Python project in 2022
For those who want a quick solution without reading all of PEP 8. The Black Python module has a fully automated solution for you.
Isaac Bythewood Isaac Bythewood
2022-07-30
Finding broken external links on websites using Scrapy
Finding broken external links on websites using Scrapy
Broken links are a problem for any content driven website as it ages, find them quickly and easily with Scrapy.
Isaac Bythewood Isaac Bythewood
2022-07-23