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:

Can you improve your Oracle database using Postgres?

Oracle is a great database. It is cutting edge and it has a huge team of developers behind it as well as massive funding.


There are not any areas where it lacks anything major that exists in other comparable databases.

The problem with Oracle is both that it is expensive in the first place, but also that all of the extras are chargeable and also expensive!

Continue reading “Can you improve your Oracle database using Postgres?”

High Availability Options in Oracle vs Postgres

Oracle is the database to beat in terms performance and features or at least is positioned that way. More importantly, if you are thinking of migrating from Oracle to Postgres to save money, you need to know that your new database has at least the same features at the one that you are moving from.


High availability is one of the most important concepts and features for a database system. For most enterprise level applications, downtime has a direct financial cost and the actual loss of some or all of your data would be catastrophic. 
You need to know that the system that you are moving to can protect your data as well as the system that you are on at the moment.

Continue reading “High Availability Options in Oracle vs Postgres”

Should you migrate to Postgres from Oracle?

The Oracle database has been the gold standard for enterprise applications for a long time now. It has great performance, solid reliability and most of the features that you could want are available. The big problem is that it is expensive. And I mean REALLY expensive. That’s just for the base product as well. All of the extra features that you might want are chargeable extras which means that wench developing for Oracle, you often have to work without some of the more advanced features because they would cost too much.

Continue reading “Should you migrate to Postgres from Oracle?”

Setting up a Postgres test cluster in vagrant

Most of the time its fine to test things out on your local machine and local installation of Postgres but often, you want more flexibility, the ability to quickly reset to a known starting point and the ability to try out different and more complex server architectures.

That is where Vagrant comes in. I use it to quickly set up Postgres clusters at different versions and different configurations.

You can find all of these in my repo at https://github.com/philmcc/postgres_clusters

For example here is a set up to allow you to set up a 3 node cluster with 1 leader and 2 followers all on postgres 9.4 and using replication slots:

Continue reading “Setting up a Postgres test cluster in vagrant”