- 3 Minutes to read
- Print
- PDF
Using PostgreSQL Streaming Replication
- 3 Minutes to read
- Print
- PDF
Streaming replication enables the continuous streaming and replication of WAL segments from the WAL directory and archived WAL segments from a primary database server to a secondary database server.
The following diagram illustrates streaming replication with continuous archiving and point-in-time recovery:
Syncing archived WAL segments is done only on the first setup of the replica.
This process is complementary to configuring continuous archiving. It protects against failures occurring on the primary database server, by streaming the WAL directory and synchronizing the database's archived WAL logs to a secondary database server.
You can also configure the replication so that the archive pool is on the passive, secondary, database and not the active database server with point-in-time recovery on the secondary.
Configuring PostgreSQL Streaming Replication
The secondary server continuously streams the primary server’s WAL segments, and synchronizes the primary database server’s archived WAL segments every 10 minutes. Streaming replication traffic runs on TCP port 5432, which means you must open these ports for communication between the primary and secondary database servers. The secondary CTERA database server acts as a standby/passive server and cannot be used for load balancing purposes.
The allocated disk space for the PostgreSQL archive pool must be at least twice the size of the storage space allocated for the CTERA Portal data pool, as described in Calculating the Minimum Space Required for the Database Backup.
The locations of the streaming and archived WAL segments are $pgdatadir/pg_wal
and $DBarchive
respectively.
To configure streaming replication:
- Using SSH, log in as
root
to your CTERA Portal secondary, replication, server. - Do one of the following:
- If the secondary, replication, server has not been initialized, browse to the server's IP address or public DNS.
- If the secondary, replication, server has been initialized but without replication, and you want to set it up as a replication server, open an SSH session to the CTERA Portal secondary, replication, server, by running the following command:
portal-manage.sh resetdb
WarningYou must not run
portal-manage.sh resetdb
on the primary database server as this will delete all the data from the database.
- Set the server as a replication of the primary database server.Note
After completing the setup wizard on an already initialized server, a new server entry is created representing the newly configured server. This makes the old server entry obsolete. You can remove the obsolete server entry by doing the following:
- Log in to the CTERA Portal as a global administrator.
- In Main > Servers locate the obsolete server entry, displayed as Not Connected.
- Select the server and click Delete.
- Log in as
root
to the CTERA Portal replication server instead of the primary database server.
You configure archiving only on the secondary server when the load on the primary server is very large. In most cases, configure streaming replication, as described above in Configuring PostgreSQL Streaming Replication. Before configuring streaming replication only on the secondary server, you must contact CTERA support.
To configure archiving only on the secondary server:
- Set up streaming replication, as described above in Configuring PostgreSQL Streaming Replication.
- Using SSH, log in as root to your CTERA Portal primary database server.
- Disable archiving on the primary server by editing the
PG_REPLIC_MODE
field in portal.cfg file as follows:
ChangePG_REPLIC_MODE=local_archive_streaming to PG_REPLIC_MODE=streaming
You do not need to restart the primary server. However, if users or any tomcat process tries to create a base backup, a warning is issued in the image log. You can ignore this warning. - Using SSH, log in as root to your secondary server.
- Enable archiving on the secondary server by editing the portal.cfg file on the secondary server, as follows:
Insert the fieldSLAVE_ARCHIVE_FORCE=yes
- Restart the server by running the following command:
portal.sh restart
If SLAVE_ARCHIVE_FORCE=no,
the secondary server archive mode is the same as the primary server mode.
Changing the SLAVE_ARCHIVE_FORCE
value always requires restarting the server.