PostgreSQL Backup Best Practice

August 28, 2024

From time to time we see queries about best practice for PostgreSQL backups. I saw one just the other day.

The first thing to note is that a backup strategy needs to be part of a more complete Disaster Recovery plan. This plan needs to identify what risks it is addressing, and how they are being mitigated. The DR plan should be regularly reviewed and tested with simulated disasters. One very well known organization I dealt with a few years ago had a variety of ways of testing their DR plan every few months, including deliberately taking down the network link between their two data center locations on the US East and West coasts and forcing a switchover of their principal server from one location to the other, as well as testing restoration from backups, including point in time recovery. This is what businesses who understand that if they lose their data they lose their business do.

The best practice I want to suggest here can be summed up in one simple phrase: use well known tools for managing backups. The two tools I have in mind are Barman and pgBackRest. Pick one of these. More importantly, don't be tempted to roll your own solution with scripts, using either operating system tools or PostgreSQL's backup tools like pg_basebackup or pg_dump. These tools I am recommending are free, and more importantly they embody years of development and testing. They use core PostgreSQL tools as building blocks, but they add lots of functionality you really want. They are not only flexible but they make sure that your backups are done right. Anything you write yourself is far less likely to be correct than these tools are.

Of the two, the one I choose is Barman, not because it is necessarily better, but because it's the one I know and have used and that I have the easiest access to support for.

There are also some commercial third party tools available that integrate with more general backup solutions. These might work well, but if you use one you will need to satisfy yourself that they work as advertised.

But please avoid the temptation to create your own. The risks are just too high.

Share this