README.md

Postrep, a basic PostgreSQL clustering tool

Postrep uses a leader election tool (Etcd 3), to achieve proper failover when the cluster leader fails, in the context of PostgreSQL's streaming replication feature.

The problem this solves

Failover between the leader and replica mode of PostgreSQL isn't automatic, and requires another protocol to decide which of the replicae becomes the leader when the previous leader fails.

Cooperation from the OS

The same user must run the PostgreSQL server and this tool. If that user is called postgres, here is a possible PolicyKit rule to make it work:

      polkit.addRule(function(action, subject) {
        if (action.id == "org.freedesktop.systemd1.manage-units" &&
            action.lookup("unit") == "postgresql-repl.service" &&
            subject.user == "postgres"){
          return polkit.Result.YES;
        }
      });

Moreover, an Etcd v3 server must be running on all servers, and pg_rewind must be callable with user=postgres to resynchronise a leader that failed or was shutdown, with the new leader.