Skip to content

Commit ce588e8

Browse files
committed
fixed Major_Upgrade Files
1 parent 86cce42 commit ce588e8

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

major_upgrade/inplace_upgrade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def do_upgrade(self):
490490
self.cluster_version, self.desired_version)
491491
return True
492492

493-
if not (self.postgresql.is_running() and self.postgresql.is_leader()):
493+
if not (self.postgresql.is_running() and self.postgresql.is_primary()):
494494
return logger.error('PostgreSQL is not running or in recovery')
495495

496496
cluster = self.dcs.get_cluster()

major_upgrade/pg_upgrade.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def restore_shared_preload_libraries(self):
3535
return True
3636

3737
def start_old_cluster(self, config, version):
38-
self.set_bin_dir(version)
38+
self._new_bin_dir = self._bin_dir
39+
self.set_bin_dir_for_version(version)
40+
self._old_bin_dir = self._bin_dir
3941

4042
# make sure we don't archive wals from the old version
4143
self._old_config_values = {'archive_mode': self.config.get('parameters').get('archive_mode')}
@@ -50,15 +52,17 @@ def get_cluster_version(self):
5052
with open(self._version_file) as f:
5153
return f.read().strip()
5254

53-
def set_bin_dir(self, version):
55+
def set_bin_dir_for_version(self, version):
5456
from spilo_commons import get_bin_dir
57+
self.set_bin_dir(get_bin_dir(version))
5558

56-
self._old_bin_dir = self._bin_dir
57-
self._bin_dir = get_bin_dir(version)
59+
def set_bin_dir(self, bin_dir):
60+
self._bin_dir = bin_dir
61+
self._available_gucs = None
5862

5963
@property
6064
def local_conn_kwargs(self):
61-
conn_kwargs = self.config.local_connect_kwargs
65+
conn_kwargs = self.connection_pool.conn_kwargs
6266
conn_kwargs['options'] = '-c synchronous_commit=local -c statement_timeout=0 -c search_path='
6367
conn_kwargs.pop('connect_timeout', None)
6468
return conn_kwargs
@@ -89,9 +93,10 @@ def drop_possibly_incompatible_objects(self):
8993
conn_kwargs['dbname'] = d
9094
with get_connection_cursor(**conn_kwargs) as cur:
9195

92-
cmd = "REVOKE EXECUTE ON FUNCTION pg_catalog.pg_switch_{0}() FROM admin".format(self.wal_name)
93-
logger.info('Executing "%s" in the database="%s"', cmd, d)
94-
cur.execute(cmd)
96+
# Role admin not existing in the containers
97+
# cmd = "REVOKE EXECUTE ON FUNCTION pg_catalog.pg_switch_{0}() FROM admin".format(self.wal_name)
98+
# logger.info('Executing "%s" in the database="%s"', cmd, d)
99+
# cur.execute(cmd)
95100

96101
logger.info('Executing "DROP FUNCTION metric_helpers.pg_stat_statements" in the database="%s"', d)
97102
cur.execute("DROP FUNCTION IF EXISTS metric_helpers.pg_stat_statements(boolean) CASCADE")
@@ -117,9 +122,15 @@ def update_extensions(self):
117122
for d in self._get_all_databases():
118123
conn_kwargs['dbname'] = d
119124
with get_connection_cursor(**conn_kwargs) as cur:
120-
cur.execute('SELECT quote_ident(extname) FROM pg_catalog.pg_extension')
121-
for extname in cur.fetchall():
122-
query = 'ALTER EXTENSION {0} UPDATE'.format(extname[0])
125+
cur.execute('SELECT quote_ident(extname), extversion FROM pg_catalog.pg_extension')
126+
for extname, version in cur.fetchall():
127+
# require manual update to 5.X+
128+
if extname == 'pg_partman' and int(version[0]) < 5:
129+
logger.warning("Skipping update of '%s' in database=%s. "
130+
"Extension version: %s. Consider manual update",
131+
extname, d, version)
132+
continue
133+
query = 'ALTER EXTENSION {0} UPDATE'.format(extname)
123134
logger.info("Executing '%s' in the database=%s", query, d)
124135
try:
125136
cur.execute(query)
@@ -168,7 +179,7 @@ def pg_upgrade(self, check=False):
168179
os.chdir(upgrade_dir)
169180

170181
pg_upgrade_args = ['-k', '-j', str(psutil.cpu_count()),
171-
'-b', self._old_bin_dir, '-B', self._bin_dir,
182+
'-b', self._old_bin_dir, '-B', self._new_bin_dir,
172183
'-d', self._data_dir, '-D', self._new_data_dir,
173184
'-O', "-c timescaledb.restoring='on'",
174185
'-O', "-c archive_mode='off'"]
@@ -180,19 +191,23 @@ def pg_upgrade(self, check=False):
180191
else:
181192
self.config.write_postgresql_conf()
182193

194+
self.set_bin_dir(self._new_bin_dir)
195+
183196
logger.info('Executing pg_upgrade%s', (' --check' if check else ''))
184197
if subprocess.call([self.pgcommand('pg_upgrade')] + pg_upgrade_args) == 0:
198+
if check:
199+
self.set_bin_dir(self._old_bin_dir)
185200
os.chdir(old_cwd)
186201
shutil.rmtree(upgrade_dir)
187202
return True
188203

189204
def prepare_new_pgdata(self, version):
190205
from spilo_commons import append_extensions
191206

192-
locale = self.query('SHOW lc_collate').fetchone()[0]
193-
encoding = self.query('SHOW server_encoding').fetchone()[0]
207+
locale = self.query('SHOW lc_collate')[0][0]
208+
encoding = self.query('SHOW server_encoding')[0][0]
194209
initdb_config = [{'locale': locale}, {'encoding': encoding}]
195-
if self.query("SELECT current_setting('data_checksums')::bool").fetchone()[0]:
210+
if self.query("SELECT current_setting('data_checksums')::bool")[0][0]:
196211
initdb_config.append('data-checksums')
197212

198213
logger.info('initdb config: %s', initdb_config)
@@ -206,7 +221,9 @@ def prepare_new_pgdata(self, version):
206221
old_version_file = self._version_file
207222
self._version_file = os.path.join(self._data_dir, 'PG_VERSION')
208223

209-
self.set_bin_dir(version)
224+
self._old_bin_dir = self._bin_dir
225+
self.set_bin_dir_for_version(version)
226+
self._new_bin_dir = self._bin_dir
210227

211228
# shared_preload_libraries for the old cluster, cleaned from incompatible/missing libs
212229
old_shared_preload_libraries = self.config.get('parameters').get('shared_preload_libraries')
@@ -239,6 +256,7 @@ def prepare_new_pgdata(self, version):
239256
self._new_data_dir, self._data_dir = self._data_dir, self._new_data_dir
240257
self.config._postgresql_conf = old_postgresql_conf
241258
self._version_file = old_version_file
259+
self.set_bin_dir(self._old_bin_dir)
242260

243261
if old_shared_preload_libraries:
244262
self.config.get('parameters')['shared_preload_libraries'] = old_shared_preload_libraries

0 commit comments

Comments
 (0)