Most people admit that backups are essential, though they also devote a very small amount of time to thinking about the topic.
The first recipe is about understanding and controlling crash recovery. You need to understand what happens if the database server crashes so that you can understand when you might need to perform a recovery operation.
The next recipe is all about planning. That's really the best place to start before you perform backups.
The physical backup mechanisms here were initially written by Simon Riggs (one of the authors of this book) for PostgreSQL 8.0 in 2004, and have been supported by him ever since, now with increasing help from the community as its popularity grows. 2ndQuadrant has also been providing database recovery services since 2004, and regrettably, many people have needed them as a result of missing or damaged backups.
It is important to note that, in the last few years, the native streaming replication protocol has become more and more relevant in PostgreSQL. It can be used for backup purposes too; not only to take a base backup with pg_basebackup, but also to stream WAL files using pg_receivewal.
As authors, we had a dilemma when planning this book. Should we introduce streaming replication before backups or leave it to the replication section? For now we decided to leave it out of this chapter and postpone it until the next. We would like your feedback on this subject for future editions of the book.
As a final note, all of the examples regarding physical backup and recovery in this chapter are thoroughly explained so that you understand what is happening behind the scenes. However, unless you have a specific task that you have to do, we highly recommend that, when in production, you use Barman (our open source backup and recovery tool), or a similar product that is specialized in this area. The last two recipes in this chapter will introduce Barman.