|
19 | 19 |
|
20 | 20 | UPDATE_BOOKMARK_PERIOD = 10000
|
21 | 21 |
|
22 |
| -def get_pg_version(cur): |
23 |
| - cur.execute("SELECT setting::int AS version FROM pg_settings WHERE name='server_version_num'") |
24 |
| - version = cur.fetchone()[0] |
25 |
| - LOGGER.debug("Detected PostgreSQL version: %s", version) |
| 22 | +def get_pg_version(conn_info): |
| 23 | + with post_db.open_connection(conn_info, False) as conn: |
| 24 | + with conn.cursor() as cur: |
| 25 | + cur.execute("SELECT setting::int AS version FROM pg_settings WHERE name='server_version_num'") |
| 26 | + version = cur.fetchone()[0] |
| 27 | + LOGGER.debug("Detected PostgreSQL version: {}".format(version)) |
26 | 28 | return version
|
27 | 29 |
|
28 | 30 |
|
@@ -60,25 +62,24 @@ def int_to_lsn(lsni):
|
60 | 62 |
|
61 | 63 |
|
62 | 64 | def fetch_current_lsn(conn_config):
|
| 65 | + version = get_pg_version(conn_config) |
| 66 | + # Make sure PostgreSQL version is 9.4 or higher |
| 67 | + # Do not allow minor versions with PostgreSQL BUG #15114 |
| 68 | + if (version >= 110000) and (version < 110002): |
| 69 | + raise Exception('PostgreSQL upgrade required to minor version 11.2') |
| 70 | + elif (version >= 100000) and (version < 100007): |
| 71 | + raise Exception('PostgreSQL upgrade required to minor version 10.7') |
| 72 | + elif (version >= 90600) and (version < 90612): |
| 73 | + raise Exception('PostgreSQL upgrade required to minor version 9.6.12') |
| 74 | + elif (version >= 90500) and (version < 90516): |
| 75 | + raise Exception('PostgreSQL upgrade required to minor version 9.5.16') |
| 76 | + elif (version >= 90400) and (version < 90421): |
| 77 | + raise Exception('PostgreSQL upgrade required to minor version 9.4.21') |
| 78 | + elif (version < 90400): |
| 79 | + raise Exception('Logical replication not supported before PostgreSQL 9.4') |
| 80 | + |
63 | 81 | with post_db.open_connection(conn_config, False) as conn:
|
64 | 82 | with conn.cursor() as cur:
|
65 |
| - # Make sure PostgreSQL version is 9.4 or higher |
66 |
| - version = get_pg_version(cur) |
67 |
| - |
68 |
| - # Do not allow minor versions with PostgreSQL BUG #15114 |
69 |
| - if (version >= 110000) and (version < 110002): |
70 |
| - raise Exception('PostgreSQL upgrade required to minor version 11.2') |
71 |
| - elif (version >= 100000) and (version < 100007): |
72 |
| - raise Exception('PostgreSQL upgrade required to minor version 10.7') |
73 |
| - elif (version >= 90600) and (version < 90612): |
74 |
| - raise Exception('PostgreSQL upgrade required to minor version 9.6.12') |
75 |
| - elif (version >= 90500) and (version < 90516): |
76 |
| - raise Exception('PostgreSQL upgrade required to minor version 9.5.16') |
77 |
| - elif (version >= 90400) and (version < 90421): |
78 |
| - raise Exception('PostgreSQL upgrade required to minor version 9.4.21') |
79 |
| - elif (version < 90400): |
80 |
| - raise Exception('Logical replication not supported before PostgreSQL 9.4') |
81 |
| - |
82 | 83 | # Use version specific lsn command
|
83 | 84 | if version >= 100000:
|
84 | 85 | cur.execute("SELECT pg_current_wal_lsn() AS current_lsn")
|
@@ -388,12 +389,13 @@ def sync_tables(conn_info, logical_streams, state, end_lsn, state_file):
|
388 | 389 | for s in logical_streams:
|
389 | 390 | sync_common.send_schema_message(s, ['lsn'])
|
390 | 391 |
|
| 392 | + version = get_pg_version(conn_info) |
| 393 | + |
391 | 394 | # Create replication connection and cursor
|
392 | 395 | conn = post_db.open_connection(conn_info, True)
|
393 | 396 | cur = conn.cursor()
|
394 | 397 |
|
395 | 398 | # Set session wal_sender_timeout for PG12 and above
|
396 |
| - version = get_pg_version(cur) |
397 | 399 | if (version >= 120000):
|
398 | 400 | wal_sender_timeout = 10800000 #10800000ms = 3 hours
|
399 | 401 | LOGGER.info("Set session wal_sender_timeout = {} milliseconds".format(wal_sender_timeout))
|
|
0 commit comments