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)