The fourth chapter of PostgreSQL replication set up asynchronous Replication (3)

Source: Internet
Author: User
Tags postgresql psql

4.3 Slave to master switch

If you want to extend the read or you want to make a backup of the data, a slave is a good thing. However, slave may not always be slave. At some point, you may need to convert slave to master. PostgreSQL provides some simple ways to do this. The first and most likely most convenient way to convert a slave to a master is to use Pg_ctl:

imac:slavehs$ pg_ctl-d. Promote

Server promoting

imac:slavehs$ psql Test

Psql (9.2.4)

Type ' help ' for help.

test=# CREATE TABLE sample (id int4);

CREATE TABLE

The promote command sends a signal to the postmaster process and converts your slave to master. Once the conversion is complete, you can connect and create the object.

In addition to the promote command, there is a second option to convert slave to master. Especially when you're trying to integrate PostgreSQL with a highly available software of your choice, creating a simple file is easier than calling the init script.

To use the file-based method, you can add the Trigger_file command to your recovery.conf file.

Trigger_file = '/tmp/start_me_up.txt '

In our example, PostgreSQL will wait for a file/tmp/start_me_up.txt to make the condition set. The content of this file is completely irrelevant; PostgreSQL simply checks to see if the file exists and, if so, stops the recovery and converts itself to master.

Creating an empty file is fairly straightforward work:

imac:slavehs$ Touch/tmp/start_me_up.txt

The database system will respond to the new file Start_me_up.txt

Fatal:terminating Walreceiver proced Fire up:

Log:trigger file found:/tmp/start_ss due to

Administrator command

Log:redo done at 0/50000e0

log:selected New Timeline Id:2

log:archive Recovery Complete

Log:database system is ready to accept connections

Log:autovacuum Launcher started

PostgreSQL will check the files you have defined in recovery.conf every five seconds. Most of the time, it's perfectly normal, and so far, fast enough.

The fourth chapter of PostgreSQL replication set up asynchronous Replication (3)

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.