Skip to content

Commit

Permalink
Ensure correct bin_dir for pg params configuration
Browse files Browse the repository at this point in the history
Make inplace upgrade code use the bin_dir of the proper version
throught the whole process, so that
ConfigHandler.write_postgresql_conf() validates provided params using
the proper PG version.
  • Loading branch information
hughcapet committed Jan 26, 2024
1 parent 4ff0bcb commit 46f3e5e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 0 additions & 3 deletions postgres-appliance/major_upgrade/inplace_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,7 @@ def do_upgrade(self):
if self.replica_connections:
from patroni.postgresql.misc import parse_lsn

# Make sure we use the pg_controldata from the correct major version
self.postgresql.set_bin_dir(self.cluster_version)
controldata = self.postgresql.controldata()
self.postgresql.set_bin_dir(self.desired_version)

checkpoint_lsn = controldata.get('Latest checkpoint location')
if controldata.get('Database cluster state') != 'shut down' or not checkpoint_lsn:
Expand Down
12 changes: 10 additions & 2 deletions postgres-appliance/major_upgrade/pg_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def restore_shared_preload_libraries(self):
return True

def start_old_cluster(self, config, version):
self._new_bin_dir = self._bin_dir
self.set_bin_dir(version)
self._old_bin_dir = self._bin_dir

# make sure we don't archive wals from the old version
self._old_config_values = {'archive_mode': self.config.get('parameters').get('archive_mode')}
Expand All @@ -53,7 +55,6 @@ def get_cluster_version(self):
def set_bin_dir(self, version):
from spilo_commons import get_bin_dir

self._old_bin_dir = self._bin_dir
self._bin_dir = get_bin_dir(version)

@property
Expand Down Expand Up @@ -168,7 +169,7 @@ def pg_upgrade(self, check=False):
os.chdir(upgrade_dir)

pg_upgrade_args = ['-k', '-j', str(psutil.cpu_count()),
'-b', self._old_bin_dir, '-B', self._bin_dir,
'-b', self._old_bin_dir, '-B', self._new_bin_dir,
'-d', self._data_dir, '-D', self._new_data_dir,
'-O', "-c timescaledb.restoring='on'",
'-O', "-c archive_mode='off'"]
Expand All @@ -180,8 +181,12 @@ def pg_upgrade(self, check=False):
else:
self.config.write_postgresql_conf()

self._bin_dir = self._new_bin_dir

logger.info('Executing pg_upgrade%s', (' --check' if check else ''))
if subprocess.call([self.pgcommand('pg_upgrade')] + pg_upgrade_args) == 0:
if check:
self._bin_dir = self._old_bin_dir
os.chdir(old_cwd)
shutil.rmtree(upgrade_dir)
return True
Expand All @@ -206,7 +211,9 @@ def prepare_new_pgdata(self, version):
old_version_file = self._version_file
self._version_file = os.path.join(self._data_dir, 'PG_VERSION')

self._old_bin_dir = self._bin_dir
self.set_bin_dir(version)
self._new_bin_dir = self._bin_dir

# shared_preload_libraries for the old cluster, cleaned from incompatible/missing libs
old_shared_preload_libraries = self.config.get('parameters').get('shared_preload_libraries')
Expand Down Expand Up @@ -239,6 +246,7 @@ def prepare_new_pgdata(self, version):
self._new_data_dir, self._data_dir = self._data_dir, self._new_data_dir
self.config._postgresql_conf = old_postgresql_conf
self._version_file = old_version_file
self._bin_dir = self._old_bin_dir

if old_shared_preload_libraries:
self.config.get('parameters')['shared_preload_libraries'] = old_shared_preload_libraries
Expand Down
1 change: 1 addition & 0 deletions postgres-appliance/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ services:
postgresql:
parameters:
wal_keep_segments: 8
jit: 'off'
postgresql:
parameters:
shared_buffers: 32MB
Expand Down

0 comments on commit 46f3e5e

Please sign in to comment.