4.6 Effective cleanup and recovery ends
In recent years, recovery.conf has become more and more powerful. Early in the beginning (before PostgreSQL 9.0), there were only Restore_command and some recovery_target_time related settings. More modern PostgreSQL versions offer more things that give you the opportunity to control your replay process in a good and professional way.
In this section, you'll learn what the settings are and how you can easily use these features.
4.6.1 gain control over restart point
So far, we have archived the Xlog indefinitely. Just like in real life, infinity is a problem-causing concept. As John Maynard Keynes has stated in his famous book, The General Theory of Employment, Interest, and money:
"In the long run, we is all dead."
What motivates the Keynes is the same for the Xlog archive; you simply can't go on. In some cases, xlog must be thrown away. To make the cleanup easier, you can put a archive_cleanup_command into recovery.conf. Just like most other commands, (for example, Restore_command), it is a generic shell script. You will put the script here and the script will be executed at each restart point. So what is the beginning of the heavy? Each time PostgreSQL transitions from file-based replay to stream-based replay, you are facing a heavy starting point. In fact, starting a stream copy again is considered to be a boot point.
Once the start point arrives, you can have PostgreSQL perform some cleanup (or anything else). It is easy to clean out old xlog or trigger some notifications.
The following script shows how you can clean up any xlog of the day before:
#!/bin/sh
Find/archive-mtime +1-exec rm-f {} \;
Keep in mind that your script can be any complex type. You must decide on an appropriate strategy to handle xlog. The situation is different for each enterprise, and you have the flexibility to control your archiving and replication behavior.
4.6.2 Adjust your recovery to the end
Recovery_end_command provide and archive_cleanup_command for similar purposes. When your recovery (or Xlog stream) is complete, it triggers some script execution.
Again, you can use it to clean up old xlog, give notifications, or perform any other action you want to perform.
The fourth chapter of PostgreSQL replication set up asynchronous replication (6)