Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure correct bin_dir for pg params configuration #966

Merged
merged 3 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 17 additions & 6 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.set_bin_dir(version)
self._new_bin_dir = self._bin_dir
self.set_bin_dir_for_version(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 @@ -50,11 +52,13 @@ def get_cluster_version(self):
with open(self._version_file) as f:
return f.read().strip()

def set_bin_dir(self, version):
def set_bin_dir_for_version(self, version):
from spilo_commons import get_bin_dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: Is this import inside the function because of circular dependencies?

self.set_bin_dir(get_bin_dir(version))

self._old_bin_dir = self._bin_dir
self._bin_dir = get_bin_dir(version)
def set_bin_dir(self, bin_dir):
self._bin_dir = bin_dir
self._available_gucs = None

@property
def local_conn_kwargs(self):
Expand Down Expand Up @@ -168,7 +172,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 +184,12 @@ def pg_upgrade(self, check=False):
else:
self.config.write_postgresql_conf()

self.set_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.set_bin_dir(self._old_bin_dir)
os.chdir(old_cwd)
shutil.rmtree(upgrade_dir)
return True
Expand All @@ -206,7 +214,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.set_bin_dir(version)
self._old_bin_dir = self._bin_dir
self.set_bin_dir_for_version(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 +249,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.set_bin_dir(self._old_bin_dir)

if old_shared_preload_libraries:
self.config.get('parameters')['shared_preload_libraries'] = old_shared_preload_libraries
Expand Down
2 changes: 2 additions & 0 deletions postgres-appliance/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ services:
loop_wait: 2
postgresql:
parameters:
wal_decode_buffer_size: '521kB'
wal_keep_segments: 8
jit: 'off'
macedigital marked this conversation as resolved.
Show resolved Hide resolved
postgresql:
parameters:
shared_buffers: 32MB
Expand Down
Loading