The fourth chapter of PostgreSQL replication set up asynchronous replication (6)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.