Skip to content

Commit d199683

Browse files
committed
fix(pg_partman): use correct library name for background worker
The pg_partman extension uses a different library name (pg_partman_bgw) than its extension name (pg_partman). This change separates the library name from the extension name to properly handle the background worker library installation and version switching.
1 parent 2bc4554 commit d199683

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

nix/ext/pg_partman.nix

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
let
1212
pname = "pg_partman";
13+
libName = "pg_partman_bgw";
1314
build =
1415
version: hash:
1516
stdenv.mkDerivation rec {
@@ -28,7 +29,7 @@ let
2829
mkdir -p $out/{lib,share/postgresql/extension}
2930
3031
# Install versioned library
31-
install -Dm755 src/*${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
32+
install -Dm755 src/${libName}${postgresql.dlSuffix} $out/lib/${libName}-${version}${postgresql.dlSuffix}
3233
3334
# Only install SQL files for the latest version
3435
if [[ "${version}" == "${latestVersion}" ]]; then
@@ -79,7 +80,7 @@ pkgs.buildEnv {
7980
echo "default_version = '${latestVersion}'"
8081
cat $out/share/postgresql/extension/${pname}--${latestVersion}.control
8182
} > $out/share/postgresql/extension/${pname}.control
82-
ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix}
83+
ln -sfn ${libName}-${latestVersion}${postgresql.dlSuffix} $out/lib/${libName}${postgresql.dlSuffix}
8384
8485
8586
# checks
@@ -90,16 +91,21 @@ pkgs.buildEnv {
9091
)
9192
9293
makeWrapper ${lib.getExe switch-ext-version} $out/bin/switch_pg_partman_version \
93-
--prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}"
94+
--prefix EXT_WRAPPER : "$out" --prefix EXT_NAME : "${pname}" --prefix LIB_NAME : "${libName}"
9495
'';
9596

9697
passthru = {
97-
inherit versions numberOfVersions switch-ext-version;
98+
inherit
99+
versions
100+
numberOfVersions
101+
switch-ext-version
102+
libName
103+
;
98104
pname = "${pname}-all";
99105
hasBackgroundWorker = true;
100106
defaultSchema = "partman";
101107
defaultSettings = {
102-
shared_preload_libraries = [ "pg_partman" ];
108+
shared_preload_libraries = [ libName ];
103109
};
104110
version =
105111
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);

nix/ext/tests/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ let
154154
sql_test_directory = Path("${../../tests}")
155155
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
156156
ext_schema = "${(installedExtension "15").defaultSchema or "public"}"
157+
lib_name = "${(installedExtension "15").libName or pname}"
158+
print(f"Running tests for extension: {lib_name}")
157159
158160
${builtins.readFile ./lib.py}
159161
@@ -177,7 +179,7 @@ let
177179
178180
if ext_has_background_worker:
179181
with subtest("Test switch_${pname}_version"):
180-
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
182+
test.check_switch_extension_with_background_worker(Path(f"${psql_15}/lib/{lib_name}.so"), "15")
181183
182184
with subtest("Check pg_regress with postgresql 15 after installing the last version"):
183185
test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)

nix/packages/switch-ext-version.nix

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,32 @@ writeShellApplication {
3131
echo " NIX_PROFILE - Path to nix profile (default: /var/lib/postgresql/.nix-profile)"
3232
echo " LIB_DIR - Override library directory"
3333
echo " EXTENSION_DIR - Override extension directory"
34+
echo " LIB_NAME - Override library name"
3435
exit 1
3536
fi
3637
3738
VERSION="$1"
38-
echo "$VERSION"
39+
40+
if [ -z "''${LIB_NAME:-}" ]; then
41+
LIB_NAME="$EXT_NAME"
42+
fi
3943
4044
# Enable overlay on the wrapper package to be able to switch version
4145
${lib.getExe overlayfs-on-package} "$EXT_WRAPPER"
4246
4347
# Check if version exists
4448
EXT_WRAPPER_LIB="$EXT_WRAPPER/lib"
45-
EXT_LIB_TO_USE="$EXT_WRAPPER_LIB/$EXT_NAME-$VERSION${postgresql.dlSuffix}"
49+
EXT_LIB_TO_USE="$EXT_WRAPPER_LIB/$LIB_NAME-$VERSION${postgresql.dlSuffix}"
4650
if [ ! -f "$EXT_LIB_TO_USE" ]; then
4751
echo "Error: Version $VERSION not found in $EXT_WRAPPER_LIB"
4852
echo "Available versions:"
4953
#shellcheck disable=SC2012
50-
ls "$EXT_WRAPPER_LIB/$EXT_NAME"-*${postgresql.dlSuffix} 2>/dev/null | sed "s/.*$EXT_NAME-/ /" | sed 's/${postgresql.dlSuffix}$//' || echo " No versions found"
54+
ls "$EXT_WRAPPER_LIB/$LIB_NAME"-*${postgresql.dlSuffix} 2>/dev/null | sed "s/.*$LIB_NAME-/ /" | sed 's/${postgresql.dlSuffix}$//' || echo " No versions found"
5155
exit 1
5256
fi
5357
5458
# Update library symlink
55-
ln -sfnv "$EXT_LIB_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME${postgresql.dlSuffix}"
59+
ln -sfnv "$EXT_LIB_TO_USE" "$EXT_WRAPPER_LIB/$LIB_NAME${postgresql.dlSuffix}"
5660
5761
# Handle extension specific steps
5862
if [ -x "''${EXTRA_STEPS:-}" ]; then

0 commit comments

Comments
 (0)