Creating a PostgreSQL clone can be surprisingly dangerous. When using a utility such as rsync, accidentally transposing the source and target can result in erasing the source PostgreSQL data directory. This is especially true when swapping from one node to another and then reversing the process. It's all too easy to accidentally invoke the wrong script when the source and target are so readily switched.
We've already established how repmgr can ease the process of clone creation, and now it's time to discuss node promotion. There are two questions we will answer in this recipe: how do we swap from one active PostgreSQL node to another, and how do we then reactivate the original node without risking our data? The second question is perhaps more important because of the fact that we will be at reduced capacity following node deactivation...