Menu

Synchronous_streaming_replication

Michael Paquier
There is a newer version of this page. You can find it here.

Basics

This part is related to all the background necessary to setup a synchronous replicated server with PostgreSQL. Before beginning the settings, it is essential to set up 2 data repositories for both slave and master.

Master settings

  • postgresql.conf

    wal_level = hot_standby
    archive_mode = on
    archive_command = 'cp -i %p $HOME/bin/postgres/archive/%f'
    max_wal_senders = 10

OK, archive_command depends on where you want to locate WAL archives

  • pg_hba.conf, necessary to allow slave contact master via replication mode

    host replication michael 127.0.0.1/32 trust
    host replication michael ::1/128 trust

Port of master is in this case 5432, so the default value.

Slave settings

  • Copy the master configuration file postgresql.conf, then modify the following lines to make it a slave.

    hot_standby = on
    port = 5433

  • recovery.conf, located in share/ as recovery.conf.sample

    standby_mode = on
    primary_conninfo = 'host=localhost port=5432'
    restore_command = 'cp -i %p $HOME/bin/postgres/archive/%f'

restore_command should call archives at the same place as archive_command for postgresql.conf.

Fallback to slave

If master dies, the following lines permit to fallback easily to slave.

 echo "standby_mode = off" >> slave/recovery.conf
 echo "port = 5432" >> slave/postgresql.conf
 ./bin/pg_ctl -D slave restart

This basically just changes the slave port to the former port of master and makes the slave react as a master node by setting standby_mode at off. After restart is completed, reconvery.conf is renamed recovery.done to avoid recovery to be done several times.

Extra notes

 pg_start_backup('backup')

This can be used to start the creation of archives backup on disk. This can accelerate the slave creation by not having to copy all the data from master.

 pg_stop_backup()

This can be used to stop on-the-way the backup archiver.

Synchronous streaming replication for Postgres-XC

This part specifies how synchronous streaming replication will be implemented in Postgres-XC. Even if functionalities in PostgreSQL 9.1 already implemented are pretty stable, some extensions related to node communication control have to be designed to have a real HA solution.

Some background

  • Postgres-XC is a multi-master database cluster based on PostgreSQL.
  • It is made of a unique global transaction manager which feeds consistently transaction IDs and snapshots in the cluster to each node.
  • Nodes are made of 2 kinds of nodes: Coordinator and Datanode.
    • Coordinators are holding other node information. A coordinator is able to communicate with other Coordinators and other Datanodes through a connection pooler. This connection pooler saves all the connection parameters to nodes (host name, port number) to be able to distribute connection with a libpq string protocol depending on database name and user name. Coordinators also have all the catalog information, and primarily the distribution information of each table in the database. With this information, Coordinator is able to push down SQL queries to correct Datanodes and then merge results that are sent back to application according a new plan type called RemoteQuery. A coordinator does not hold table data, and all the data contained each Coordinator is the same. So one Coordinator is the clone of another one.
    • Datanodes react more or less like a PostgreSQL normal instance. They hold database data. What has been added is an interface to permit Datanodes to receive from Coordinators transaction IDs, snapshots, timestamp values instead of requesting them locally.

Limitations

  • Postgres-XC does not support yet tuple relocation from one node to another (impossible to update for instance column that holds the distribution key), so this design is limited to the case where the cluster has a fixed number of master nodes (for Datanodes and Coordinators (?)).
  • It is not thought here about trying to add or delete a Datanode on the fly. By that, it means that cluster configuration is not changed in a way that it modifies the node number and data distribution.
  • With those assumptions what remains is a cluster with a fixed size

Specifications

Here are the list of functionalities that will be added for the support of synchronous streaming replication. Most of them concern node management, master/slave identification and slave promotion system.

  • In no way Postgres-XC nodes are thought as being able to make system calls to be able to kick a slave initdb or something like this. NO WAY!

Catalog addition

A catalog called pgxc_nodes will be added with the following columns:

  • node type
  • node ID number
  • node port number
  • node host/IP
  • node immediate master ID

This table has as a primary key constraint on node number and node type.

SQL interface


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.