From 21e02e1ae3063402199c5bc3b3b083b7bc1f3aad Mon Sep 17 00:00:00 2001 From: Alexey Savchkov Date: Fri, 26 Jun 2026 11:59:29 +0700 Subject: [PATCH 1/9] 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 ff7900a..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_num = testgres.parse_pg_version(self._pg_config['VERSION']) - parts = [*version_num.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 0416c3e164cda9dc92d2d330f8f99c63b9066c78 Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 29 Jun 2026 11:39:54 +0200 Subject: [PATCH 2/9] 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 3c0c6f109d3ab7c5e785690c345cc1d508e90ab3 Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 29 Jun 2026 15:23:34 +0200 Subject: [PATCH 3/9] 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) From 749b8dcc80b1306e8394948def8c098cbc017aa5 Mon Sep 17 00:00:00 2001 From: dura0ok Date: Mon, 29 Jun 2026 17:58:36 +0700 Subject: [PATCH 4/9] Fix trial PGPRO version parse (#19) --- pg_probackup2/init_helpers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index d49dfd4..99b71c0 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -42,6 +42,7 @@ def __init__(self): else: self.verbose = False +<<<<<<< HEAD os_ops = testgres.LocalOperations() pg_bin = os.getenv('PG_BIN', shutil.which('postgres')) @@ -68,6 +69,16 @@ def __init__(self): [pg_bin, "-C", "server_version"], encoding='utf-8').rstrip('develalphabetapre\n') parts = [*server_version.split('.'), '0', '0'][:3] +======= + 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_num = testgres.parse_pg_version(self._pg_config['VERSION']) + parts = [*version_num.split('.'), '0', '0'][:3] +>>>>>>> 6d99741 (Fix trial PGPRO version parse (#19)) parts[0] = re.match(r'\d+', parts[0]).group() self.pg_config_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) From 9a22b673c18801459e55d2d1468edd4f04117641 Mon Sep 17 00:00:00 2001 From: Alexey Savchkov Date: Fri, 26 Jun 2026 11:59:29 +0700 Subject: [PATCH 5/9] Don't use pg_config --- pg_probackup2/init_helpers.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index 99b71c0..d4e1b1b 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -42,7 +42,6 @@ def __init__(self): else: self.verbose = False -<<<<<<< HEAD os_ops = testgres.LocalOperations() pg_bin = os.getenv('PG_BIN', shutil.which('postgres')) @@ -69,18 +68,23 @@ def __init__(self): [pg_bin, "-C", "server_version"], encoding='utf-8').rstrip('develalphabetapre\n') parts = [*server_version.split('.'), '0', '0'][:3] -======= - 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_num = testgres.parse_pg_version(self._pg_config['VERSION']) - parts = [*version_num.split('.'), '0', '0'][:3] ->>>>>>> 6d99741 (Fix trial PGPRO version parse (#19)) + + ldd = subprocess.run( + ['ldd', pg_bin], + capture_output=True, + encoding='utf-8').stdout + self.is_lz4_enabled = 'liblz4.so' in ldd + + server_version_out = subprocess.run( + [pg_bin, "-C", "server_version"], + capture_output=True, + encoding='utf-8').stdout + server_version = testgres.parse_pg_version(server_version_out) + 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) + num_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) + # For backward compatibility + self.pg_config_version = num_version os.environ['LANGUAGE'] = 'en' # set default locale language to en. All messages will use this locale test_env = os.environ.copy() @@ -198,7 +202,7 @@ def __init__(self): self.old_probackup_version = match.group(0) if match else None self.remote = test_env.get('PGPROBACKUP_SSH_REMOTE', None) == 'ON' - self.ptrack = test_env.get('PG_PROBACKUP_PTRACK', None) == 'ON' and self.pg_config_version >= 110000 + self.ptrack = test_env.get('PG_PROBACKUP_PTRACK', None) == 'ON' and num_version >= 110000 self.wal_tree_enabled = test_env.get('PG_PROBACKUP_WAL_TREE_ENABLED', None) == 'ON' self.bckp_source = test_env.get('PG_PROBACKUP_SOURCE', 'pro').lower() From 1056dc04644489ece13d9546cc17b323414e98ad Mon Sep 17 00:00:00 2001 From: vshepard Date: Mon, 29 Jun 2026 11:39:54 +0200 Subject: [PATCH 6/9] Replace subprocess on os_ops --- pg_probackup2/init_helpers.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index d4e1b1b..d8e4504 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -68,19 +68,6 @@ def __init__(self): [pg_bin, "-C", "server_version"], encoding='utf-8').rstrip('develalphabetapre\n') parts = [*server_version.split('.'), '0', '0'][:3] - - ldd = subprocess.run( - ['ldd', pg_bin], - capture_output=True, - encoding='utf-8').stdout - self.is_lz4_enabled = 'liblz4.so' in ldd - - server_version_out = subprocess.run( - [pg_bin, "-C", "server_version"], - capture_output=True, - encoding='utf-8').stdout - server_version = testgres.parse_pg_version(server_version_out) - parts = [*server_version.split('.'), '0', '0'][:3] parts[0] = re.match(r'\d+', parts[0]).group() num_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) # For backward compatibility From 13b7bfc48a59f78f19b9c642ccae614dc07c5af7 Mon Sep 17 00:00:00 2001 From: Alexey Savchkov Date: Wed, 1 Jul 2026 18:46:34 +0700 Subject: [PATCH 7/9] PG_BIN should point to a directory rather than to a file --- pg_probackup2/init_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index d8e4504..441ffca 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -44,11 +44,11 @@ def __init__(self): os_ops = testgres.LocalOperations() - pg_bin = os.getenv('PG_BIN', shutil.which('postgres')) + pg_bin = os.getenv('PG_BIN', os.path.dirname(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 directory. Specify the path to the directory in PG_BIN or put it to the system PATH.") pgpro_edition = os_ops.exec_command( [pg_bin, "-C", "pgpro_edition"], From f162361b813672c210f2c66fe1cc533662779452 Mon Sep 17 00:00:00 2001 From: vshepard Date: Tue, 7 Jul 2026 13:29:25 +0200 Subject: [PATCH 8/9] Small updates --- pg_probackup2/init_helpers.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index 441ffca..4593f75 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -44,16 +44,16 @@ def __init__(self): os_ops = testgres.LocalOperations() - pg_bin = os.getenv('PG_BIN', os.path.dirname(shutil.which('postgres'))) - - if pg_bin is None: + try: + pg_bin = testgres.get_bin_dir(os_ops) + except Exception as e: raise Exception( - "Failed to determine the Postgres binary directory. Specify the path to the directory in PG_BIN or put it to the system PATH.") + "Failed to determine the Postgres binary directory. Specify the path to the directory in PG_BIN or put it to the system PATH.") from e + postgres = os_ops.build_path(pg_bin, 'postgres') pgpro_edition = os_ops.exec_command( - [pg_bin, "-C", "pgpro_edition"], - encoding='utf-8', - ignore_errors=True)[:-1] # remove the trailing newline + [postgres, "-C", "pgpro_edition"], + encoding='utf-8').strip() self.is_enterprise = pgpro_edition == 'enterprise' self.is_shardman = pgpro_edition == 'shardman' self.is_pgpro = pgpro_edition != '' @@ -121,8 +121,7 @@ def __init__(self): test_env["PGPROBACKUPBIN"])) if not self.probackup_path: - probackup_path_tmp = os.path.join( - os.path.dirname(pg_bin), 'pg_probackup') + probackup_path_tmp = os_ops.build_path(pg_bin, 'pg_probackup') if os.path.isfile(probackup_path_tmp): if not os.access(probackup_path_tmp, os.X_OK): From d8307ccd70368cb0f7bdcac778dfc4d9631fb8a4 Mon Sep 17 00:00:00 2001 From: Alexey Savchkov Date: Wed, 8 Jul 2026 10:48:22 +0700 Subject: [PATCH 9/9] Revert unnecessary changes --- pg_probackup2/init_helpers.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/pg_probackup2/init_helpers.py b/pg_probackup2/init_helpers.py index 4593f75..b40a021 100644 --- a/pg_probackup2/init_helpers.py +++ b/pg_probackup2/init_helpers.py @@ -44,31 +44,35 @@ def __init__(self): os_ops = testgres.LocalOperations() - try: - pg_bin = testgres.get_bin_dir(os_ops) - except Exception as e: + pg_bin = testgres.get_bin_dir(os_ops) + if pg_bin is None: raise Exception( - "Failed to determine the Postgres binary directory. Specify the path to the directory in PG_BIN or put it to the system PATH.") from e + "Failed to determine the Postgres binary directory. Specify the path to the directory in PG_BIN or put it to the system PATH.") postgres = os_ops.build_path(pg_bin, 'postgres') pgpro_edition = os_ops.exec_command( [postgres, "-C", "pgpro_edition"], - encoding='utf-8').strip() + 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 = os_ops.exec_command( - ['ldd', pg_bin], + ['ldd', postgres], 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').rstrip('develalphabetapre\n') + server_version_out = os_ops.exec_command( + [postgres, "-C", "server_version"], + encoding='utf-8') + server_version = testgres.parse_pg_version(server_version_out) parts = [*server_version.split('.'), '0', '0'][:3] parts[0] = re.match(r'\d+', parts[0]).group() + # Server_version consists of two fields (x.y) so num_version always ends with 00 num_version = reduce(lambda v, x: v * 100 + int(x), parts, 0) # For backward compatibility self.pg_config_version = num_version