From 7eb7137c84e6d70019ae5cd965792350e688531b Mon Sep 17 00:00:00 2001 From: Alexey Savchkov Date: Fri, 26 Jun 2026 11:59:29 +0700 Subject: [PATCH 1/3] Don't use pg_config --- pg_probackup2/init_helpers.py | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index f6bd20c..be84ddf 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -42,14 +42,32 @@ def __init__(self): else: self.verbose = False - self._pg_config = testgres.get_pg_config() - self.is_enterprise = self._pg_config.get('PGPRO_EDITION', None) == 'enterprise' - self.is_shardman = self._pg_config.get('PGPRO_EDITION', None) == 'shardman' - self.is_pgpro = 'PGPRO_EDITION' in self._pg_config - self.is_nls_enabled = 'enable-nls' in self._pg_config['CONFIGURE'] - self.is_lz4_enabled = '-llz4' in self._pg_config['LIBS'] - version = self._pg_config['VERSION'].rstrip('develalphabetapre') - parts = [*version.split(' ')[1].split('.'), '0', '0'][:3] + pg_bin = os.getenv('PG_BIN', shutil.which('postgres')) + + if pg_bin is None: + raise Exception( + "Failed to determine the Postgres binary. Specify the path to 'postgres' in PG_BIN or put it to the system PATH.') + + pgpro_edition = subprocess.run( + [pg_bin, "-C", "pgpro_edition"], + capture_output=True, + encoding='utf-8').stdout[:-1] # remove the trailing newline + self.is_enterprise = pgpro_edition == 'enterprise' + self.is_shardman = pgpro_edition == 'shardman' + self.is_pgpro = pgpro_edition != '' + # TODO: Always test with NLS support and remove this flag + self.is_nls_enabled = True + ldd = subprocess.run( + ['ldd', pg_bin], + capture_output=True, + encoding='utf-8').stdout + self.is_lz4_enabled = 'liblz4.so' in ldd + + server_version = subprocess.run( + [pg_bin, "-C", "server_version"], + capture_output=True, + encoding='utf-8').stdout.rstrip('develalphabetapre\n') + parts = [*server_version.split('.'), '0', '0'][:3] parts[0] = re.match(r'\d+', parts[0]).group() self.pg_config_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) @@ -102,7 +120,7 @@ def __init__(self): if not self.probackup_path: probackup_path_tmp = os.path.join( - testgres.get_pg_config()['BINDIR'], 'pg_probackup') + os.path.dirname(pg_bin), 'pg_probackup') if os.path.isfile(probackup_path_tmp): if not os.access(probackup_path_tmp, os.X_OK): From 37b22cdec2babbd48ce5474f4e03ba76e8bac44d Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 29 Jun 2026 11:39:54 +0200 Subject: [PATCH 2/3] Replace subprocess on os_ops --- pg_probackup2/init_helpers.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index be84ddf..fe7817c 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -42,31 +42,33 @@ def __init__(self): else: self.verbose = False + os_ops = testgres.LocalOperations() + pg_bin = os.getenv('PG_BIN', shutil.which('postgres')) if pg_bin is None: raise Exception( - "Failed to determine the Postgres binary. Specify the path to 'postgres' in PG_BIN or put it to the system PATH.') + "Failed to determine the Postgres binary. Specify the path to 'postgres' in PG_BIN or put it to the system PATH.") - pgpro_edition = subprocess.run( + pgpro_edition = os_ops.exec_command( [pg_bin, "-C", "pgpro_edition"], - capture_output=True, - encoding='utf-8').stdout[:-1] # remove the trailing newline + encoding='utf-8', + ignore_errors=True)[:-1] # remove the trailing newline self.is_enterprise = pgpro_edition == 'enterprise' self.is_shardman = pgpro_edition == 'shardman' self.is_pgpro = pgpro_edition != '' # TODO: Always test with NLS support and remove this flag self.is_nls_enabled = True - ldd = subprocess.run( + ldd = os_ops.exec_command( ['ldd', pg_bin], - capture_output=True, - encoding='utf-8').stdout + encoding='utf-8', + ignore_errors=True) self.is_lz4_enabled = 'liblz4.so' in ldd - server_version = subprocess.run( + server_version = os_ops.exec_command( [pg_bin, "-C", "server_version"], - capture_output=True, - encoding='utf-8').stdout.rstrip('develalphabetapre\n') + encoding='utf-8', + ignore_errors=True).rstrip('develalphabetapre\n') parts = [*server_version.split('.'), '0', '0'][:3] parts[0] = re.match(r'\d+', parts[0]).group() self.pg_config_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) From 4637e18b5529fa4cc9ca4ddfa3c71de7255725b7 Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 29 Jun 2026 15:23:34 +0200 Subject: [PATCH 3/3] remove ignore_errors=True --- pg_probackup2/init_helpers.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index fe7817c..d49dfd4 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -61,14 +61,12 @@ def __init__(self): self.is_nls_enabled = True ldd = os_ops.exec_command( ['ldd', pg_bin], - encoding='utf-8', - ignore_errors=True) + encoding='utf-8') self.is_lz4_enabled = 'liblz4.so' in ldd server_version = os_ops.exec_command( [pg_bin, "-C", "server_version"], - encoding='utf-8', - ignore_errors=True).rstrip('develalphabetapre\n') + encoding='utf-8').rstrip('develalphabetapre\n') parts = [*server_version.split('.'), '0', '0'][:3] parts[0] = re.match(r'\d+', parts[0]).group() self.pg_config_version = reduce(lambda v, x: v * 100 + int(x), parts, 0)