From ce254ccde31d80962e7488701cc6ee01006caa56 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 12 Mar 2015 14:15:00 +0900 Subject: [PATCH] Add instructions for upgrading from repmgr2 to repmgr3 --- README.md | 12 +++++++ sql/repmgr2_repmgr3.sql | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 sql/repmgr2_repmgr3.sql diff --git a/README.md b/README.md index 7896dd4b..d01c3a29 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,18 @@ New features in `repmgr 3` include: * replication slot support (PostgreSQL 9.4 and later) * usability improvements, including better logging and error reporting +Upgrading from repmgr 2 +----------------------- + +`repmgr 3` is largely compatible with `repmgr 2`; the only step required +to upgrade is to update the `repl_nodes` table to the definition needed +by `repmgr 3`. See the file `sql/repmgr2_repmgr3.sql` for details on how +to do this. + +`repmgrd` must *not* be running while `repl_nodes` is being updated. + +Existing `repmgr.conf` files can be retained as-is. + Conceptual Overview ------------------- diff --git a/sql/repmgr2_repmgr3.sql b/sql/repmgr2_repmgr3.sql new file mode 100644 index 00000000..99502b12 --- /dev/null +++ b/sql/repmgr2_repmgr3.sql @@ -0,0 +1,76 @@ +/* + * Update a repmgr 2.x installation to repmgr 3.0 + * ---------------------------------------------- + * + * 1. Stop any running repmgrd instances + * 2. On the master node, execute the SQL statements listed below, + * taking care to identify the master node and any inactive + * nodes + * 3. Restart repmgrd (being sure to use repmgr 3.0) + */ + +/* + * Set the search path to the name of the schema used by + * your rempgr installation + * (this should be "repmgr_" + the cluster name defined in + * 'repmgr.conf') + */ + +-- SET search_path TO 'name_of_repmgr_schema'; + +BEGIN; + +ALTER TABLE repl_nodes RENAME TO repl_nodes2_0; + +CREATE TABLE repl_nodes ( + id INTEGER PRIMARY KEY, + type TEXT NOT NULL CHECK (type IN('master','standby','witness')), + upstream_node_id INTEGER NULL REFERENCES repl_nodes (id), + cluster TEXT NOT NULL, + name TEXT NOT NULL, + conninfo TEXT NOT NULL, + slot_name TEXT NULL, + priority INTEGER NOT NULL, + active BOOLEAN NOT NULL DEFAULT TRUE +); + +INSERT INTO repl_nodes + (id, type, cluster, name, conninfo, priority) + SELECT id, + CASE + WHEN witness IS TRUE THEN 'witness' + ELSE 'standby' + END AS type, + cluster, + name, + conninfo, + priority + FROM repl_nodes2_0; + +/* + * You'll need to set the master explicitly; the following query + * should identify the master node ID but will only work if all + * standby servers are connected: + * + * SELECT id FROM repmgr_test.repl_nodes WHERE name NOT IN (SELECT application_name FROM pg_stat_replication) + * + * If in doubt, execute 'repmgr cluster show' will definitively identify + * the master. + */ +UPDATE repl_nodes SET type = 'master' WHERE id = $master_id; + +/* If any nodes are known to be inactive, update them here */ + +-- UPDATE repl_nodes SET active = FALSE WHERE id IN (...); + +/* When you're sure of your changes, commit them */ + +-- COMMIT; + + +/* + * execute the following command when you are sure you no longer + * require the old table: + */ + +-- DROP TABLE repl_nodes2_0;