Merge lp:~cjwatson/launchpad/postgresql-10-replication into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18893
Proposed branch: lp:~cjwatson/launchpad/postgresql-10-replication
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/postgresql-version-checks
Diff against target: 109 lines (+31/-11)
4 files modified
database/replication/walblock.py (+2/-2)
database/schema/dbcontroller.py (+20/-5)
database/schema/full-update.py (+8/-3)
utilities/launchpad-database-setup (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/postgresql-10-replication
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+363972@code.launchpad.net

Commit message

Update replication machinery to cope with changes in PostgreSQL 10.

Description of the change

I don't have a setup that allows me to test any of this at the moment, so I'm flying somewhat blind.

I've left the 9.3/xlog reference in database/replication/Makefile alone. Precedent seems to be that we just update that once staging has been upgraded.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/replication/walblock.py'
2--- database/replication/walblock.py 2014-01-13 07:38:24 +0000
3+++ database/replication/walblock.py 2019-03-05 13:36:54 +0000
4@@ -22,8 +22,8 @@
5 help="Block if there are more than N unshipped WAL files.", default=25)
6 parser.add_option(
7 "-d", dest="wal_dir", metavar="DIR", type="string",
8- help="Path to pg_xlog directory",
9- default="/var/lib/postgresql/9.1/main/pg_xlog")
10+ help="Path to pg_wal directory",
11+ default="/var/lib/postgresql/10/main/pg_wal")
12 parser.add_option(
13 "-v", "--verbose", action="store_true", default=False, help="Verbose")
14 options, args = parser.parse_args()
15
16=== modified file 'database/schema/dbcontroller.py'
17--- database/schema/dbcontroller.py 2012-09-28 06:15:58 +0000
18+++ database/schema/dbcontroller.py 2019-03-05 13:36:54 +0000
19@@ -39,7 +39,10 @@
20 cur = con.cursor()
21
22 # Force a WAL switch, returning the current position.
23- cur.execute('SELECT pg_switch_xlog()')
24+ if con.server_version >= 100000:
25+ cur.execute('SELECT pg_switch_wal()')
26+ else:
27+ cur.execute('SELECT pg_switch_xlog()')
28 wal_point = cur.fetchone()[0]
29 start_time = time.time()
30 while timeout is None or time.time() < start_time + timeout:
31@@ -103,7 +106,10 @@
32 try:
33 con = pg_connect(conn_str)
34 cur = con.cursor()
35- cur.execute('select pg_xlog_replay_pause()')
36+ if con.server_version >= 100000:
37+ cur.execute('select pg_wal_replay_pause()')
38+ else:
39+ cur.execute('select pg_xlog_replay_pause()')
40 except psycopg2.Error, x:
41 self.log.error(
42 'Unable to pause replication to %s (%s).'
43@@ -119,7 +125,10 @@
44 try:
45 con = pg_connect(conn_str)
46 cur = con.cursor()
47- cur.execute('select pg_xlog_replay_resume()')
48+ if con.server_version >= 100000:
49+ cur.execute('select pg_wal_replay_resume()')
50+ else:
51+ cur.execute('select pg_xlog_replay_resume()')
52 except psycopg2.Error, x:
53 success = False
54 self.log.error(
55@@ -140,11 +149,17 @@
56 try:
57 con = pg_connect(conn_str)
58 cur = con.cursor()
59- cur.execute("SELECT pg_is_xlog_replay_paused()")
60+ if con.server_version >= 100000:
61+ cur.execute("SELECT pg_is_wal_replay_paused()")
62+ else:
63+ cur.execute("SELECT pg_is_xlog_replay_paused()")
64 replication_paused = cur.fetchone()[0]
65 if replication_paused:
66 self.log.warn("Replication paused on %s. Resuming.", name)
67- cur.execute("SELECT pg_xlog_replay_resume()")
68+ if con.server_version >= 100000:
69+ cur.execute("SELECT pg_wal_replay_resume()")
70+ else:
71+ cur.execute("SELECT pg_xlog_replay_resume()")
72 wait_for_sync = True
73 except psycopg2.Error, x:
74 success = False
75
76=== modified file 'database/schema/full-update.py'
77--- database/schema/full-update.py 2012-10-12 11:49:37 +0000
78+++ database/schema/full-update.py 2019-03-05 13:36:54 +0000
79@@ -175,9 +175,14 @@
80 # Resume replication.
81 replication_paused = not controller.resume_replication()
82 if replication_paused:
83- log.error(
84- "Failed to resume replication. Run pg_xlog_replay_pause() "
85- "on all slaves to manually resume.")
86+ if master_con.server_version >= 100000:
87+ log.error(
88+ "Failed to resume replication. Run pg_wal_replay_pause() "
89+ "on all slaves to manually resume.")
90+ else:
91+ log.error(
92+ "Failed to resume replication. Run pg_xlog_replay_pause() "
93+ "on all slaves to manually resume.")
94 else:
95 if controller.sync():
96 log.info('Slaves in sync. Updates replicated.')
97
98=== modified file 'utilities/launchpad-database-setup'
99--- utilities/launchpad-database-setup 2018-05-14 13:11:14 +0000
100+++ utilities/launchpad-database-setup 2019-03-05 13:36:54 +0000
101@@ -19,7 +19,7 @@
102 # initial Launchpad setup on an otherwise unconfigured postgresql instance
103
104 pgversion=
105-for try_pgversion in 9.3 9.5 9.6
106+for try_pgversion in 9.3 9.5 9.6 10
107 do
108 sudo grep -qs "^auto" /etc/postgresql/$try_pgversion/main/start.conf
109 if [ $? -eq 0 ]; then