You can fail over from the master server to a standby server. A standby server is always kept in a near-ready state by periodically replicating log files from the backup of the master server to a synced standby server.
If the master server fails, then do not wait to restore the failed master server. You can quickly replace the failed master server with the standby server.
Before You Begin
-
Identify an optimum log file backup schedule for the master server, so that the standby server is always in sync.
-
Verify that log file backup operations are scheduled on the master server. If the backup operations are not scheduled, then the scheduled replication restore will not run.
Procedure
-
From the standby server, go to the PostgreSQL data directory, and identify the trigger file as shown in the following example:
bash-4.1$ cat recovery.conf restore_command = 'cp /opt/PostgreSQL/9.5/wal/%f %p' standby_mode = 'on' trigger_file = '/tmp/postgresql-repl-5432.trigger' bash-4.1$ touch /tmp/postgresql-repl-5432.trigger bash-4.1$
-
Create the trigger file.
For a Windows standby server, you can create the trigger file manually.
For a UNIX standby server, to create the trigger file, you can run a command similar to the example shown below:
touch /tmp/postgresql-repl-5432.trigger
-
Delete the old replication schedule.
If you have a new master server that is synchronized with the standby server, then configure a new replication schedule.
Note
After a failover, if you have a new setup of the master server and a standby server, then create a new replication schedule.