Find the size of a table in Postgres

You often need to know the size of a table in postgres and there is no particularly easy way to get that information directly from the psql client.

Fortunately, all of the information is in there and is available through nice simple functions.

All you have to do is pull it together and a stock query will normally do.

The below query will get you a list of all of the tables in your database, it will show you the size of the associated indexes as well as the size of the associated TOAST objects.

If you want the size of your database, I would tend to just do a ‘\l+’ in psql but if you want to do it in SQL for some reason then you can just do:

And then if you want the size of all of your databases then its a simple change so that it looks like:

And finally, if you want a size breakdown of all of the objects in your database – so that you can see all of the indexes as well as the tables then you can find that with:

Leave a Reply

Your email address will not be published. Required fields are marked *