Skip to content

chore: add timescaledb 2.9.1; wrappers upgrade fix; wrappers & plv8 naming fix #1259

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

Merged
merged 25 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7e2735f
fix (15.6): wrappers for pg_upgrade
pcnc Oct 1, 2024
1022585
fix: account for `public` grantee
soedirgo Sep 26, 2024
b13bea9
fix(ci): respect postgresVersion input (#1237)
soedirgo Sep 26, 2024
c31f5a3
feat: bump gotrue version to v2.162.0 (#1241)
kangmingtay Sep 28, 2024
853ab55
fix: only grant pg_read_all_data if it exists (#1242)
soedirgo Sep 30, 2024
23f5c7e
chore: workflow fix
pcnc Oct 1, 2024
989415b
Merge branch 'release/15.6' into pcnc/wrappers-15.6
pcnc Oct 2, 2024
5e986bb
fix: collision when patching wrappers lib locations for upgrades
pcnc Oct 2, 2024
481f1da
Merge branch 'release/15.6' into pcnc/wrappers-15.6
pcnc Oct 3, 2024
be24e6a
chore: timescaledb 2.9.1
pcnc Oct 4, 2024
c73ab37
feat: bump auth 2.162.1 on 15.6 (#1256)
hf Oct 3, 2024
32f076d
fix(15.6): disable pg_stat_monitor (#1260)
pcnc Oct 4, 2024
dd8b87a
Merge branch 'release/15.6' into pcnc/wrappers-15.6
pcnc Oct 4, 2024
aebbd63
Merge branch 'timescaledb-2.9.1' into pcnc/15.6-test
pcnc Oct 14, 2024
a46c06d
fix: rm version num from plv8 lib
samrose Oct 8, 2024
17f9019
feat: post build rename .so file and edit sql to point to new name
samrose Oct 4, 2024
94b89a3
chore: wrappers lib rename
samrose Oct 4, 2024
fa488e9
chore: bump pg version
pcnc Oct 14, 2024
697fc6d
fix: paths
pcnc Oct 14, 2024
ed36aa1
fix: wrappers; plv8; backwards compat
pcnc Oct 14, 2024
7cb3e6e
chore: stop patching wrappers
pcnc Oct 14, 2024
55397c3
chore: bump pg version
pcnc Oct 14, 2024
7fa1ba4
chore: remove unneeded variable
pcnc Oct 14, 2024
2537aa0
fix: remove timescaledb 2.9.1 control file
pcnc Oct 15, 2024
1fac4f2
chore: fix interface
pcnc Oct 15, 2024
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
55 changes: 0 additions & 55 deletions ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")

POSTGRES_CONFIG_PATH="/etc/postgresql/postgresql.conf"
PGBINOLD="/usr/lib/postgresql/bin"
PGLIBOLD="/usr/lib/postgresql/lib"

PG_UPGRADE_BIN_DIR="/tmp/pg_upgrade_bin/$PGVERSION"
NIX_INSTALLER_PATH="/tmp/persistent/nix-installer"
Expand Down Expand Up @@ -181,58 +180,6 @@ EOF
done
}

function patch_wrappers {
local IS_NIX_UPGRADE=$1

WRAPPERS_ENABLED=$(run_sql -A -t -c "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'wrappers');")
if [ "$WRAPPERS_ENABLED" = "f" ]; then
echo "Wrappers extension not enabled. Skipping."
return
fi

# This is a workaround for older versions of wrappers which don't have the expected
# naming scheme, containing the version in their library's file name
# e.g. wrappers-0.1.16.so, rather than wrappers.so
# pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's
# library directory, so we're making sure the new version has the expected (old version's)
# file name.
# After the upgrade completes, the new version's library file is used.
# i.e.
# - old version: wrappers-0.1.16.so
# - new version: wrappers-0.1.18.so
# - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so
if [ "$IS_NIX_UPGRADE" = "true" ]; then
if [ -d "$PGLIBOLD" ]; then
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
OLD_LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")

find /nix/store/ -name "wrappers*so" -print0 | while read -r -d $'\0' WRAPPERS_LIB_PATH; do
if [ -f "$WRAPPERS_LIB_PATH" ]; then
WRAPPERS_LIB_PATH_DIR=$(dirname "$WRAPPERS_LIB_PATH")
if [ "$WRAPPERS_LIB_PATH" != "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" ]; then
echo "Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}"
cp "$WRAPPERS_LIB_PATH" "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" || true
fi
fi
done
fi
else
if [ -d "$PGLIBOLD" ]; then
WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit)
if [ -f "$WRAPPERS_LIB_PATH" ]; then
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then
LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then
echo "Copying $WRAPPERS_LIB_PATH to $PGLIBNEW/${LIB_FILE_NAME}"
cp "$WRAPPERS_LIB_PATH" "$PGLIBNEW/${LIB_FILE_NAME}" || true
fi
fi
fi
fi
fi
}

function initiate_upgrade {
mkdir -p "$MOUNT_POINT"
SHARED_PRELOAD_LIBRARIES=$(cat "$POSTGRES_CONFIG_PATH" | grep shared_preload_libraries | sed "s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/")
Expand Down Expand Up @@ -409,8 +356,6 @@ function initiate_upgrade {
export LD_LIBRARY_PATH="${PGLIBNEW}"
fi

patch_wrappers "$IS_NIX_UPGRADE"

echo "9. Creating new data directory, initializing database"
chown -R postgres:postgres "$MOUNT_POINT/"
rm -rf "${PGDATANEW:?}/"
Expand Down
2 changes: 1 addition & 1 deletion common-nix.vars.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
postgres-version = "15.6.1.129"
postgres-version = "15.6.1.130"
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
ourExtensions = [
./nix/ext/rum.nix
./nix/ext/timescaledb.nix
./nix/ext/timescaledb-2.9.1.nix
./nix/ext/pgroonga.nix
./nix/ext/index_advisor.nix
./nix/ext/wal2json.nix
Expand Down
16 changes: 10 additions & 6 deletions nix/ext/plv8.nix
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ stdenv.mkDerivation (finalAttrs: {
# so changing them does not cause issues.
mv "$out/nix/store"/*/* "$out"
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"

mv "$out/lib/plv8-${finalAttrs.version}.so" "$out/lib/plv8.so"
ln -s "$out/lib/plv8.so" "$out/lib/plv8-${finalAttrs.version}.so"
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plv8.control"
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plcoffee.control"
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plls.control"
${lib.optionalString stdenv.isDarwin ''
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}.so
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8.so
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8.so
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8.so
''}

${lib.optionalString (!stdenv.isDarwin) ''
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
''}
'';

Expand Down
51 changes: 51 additions & 0 deletions nix/ext/timescaledb-2.9.1.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{ lib, stdenv, fetchFromGitHub, cmake, postgresql, openssl, libkrb5 }:

stdenv.mkDerivation rec {
pname = "timescaledb-apache";
version = "2.9.1";

nativeBuildInputs = [ cmake ];
buildInputs = [ postgresql openssl libkrb5 ];

src = fetchFromGitHub {
owner = "timescale";
repo = "timescaledb";
rev = version;
hash = "sha256-fvVSxDiGZAewyuQ2vZDb0I6tmlDXl6trjZp8+qDBtb8=";
};

cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=1" ]
++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];

# Fix the install phase which tries to install into the pgsql extension dir,
# and cannot be manually overridden. This is rather fragile but works OK.
postPatch = ''
for x in CMakeLists.txt sql/CMakeLists.txt; do
substituteInPlace "$x" \
--replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
done

for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
substituteInPlace "$x" \
--replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
done
'';


# timescaledb-2.9.1.so already exists in the lib directory
# we have no need for the timescaledb.so or control file
postInstall = ''
rm $out/lib/timescaledb.so
rm $out/share/postgresql/extension/timescaledb.control
'';

meta = with lib; {
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
homepage = "https://www.timescale.com/";
changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.asl20;
broken = versionOlder postgresql.version "13";
};
}
64 changes: 46 additions & 18 deletions nix/ext/wrappers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,52 @@ buildPgrxExtension_0_11_3 rec {
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
'';

postInstall = ''
echo "Creating SQL files for previous versions..."
current_version="${version}"
sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"

if [ -f "$sql_file" ]; then
while read -r previous_version; do
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql"
echo "Creating $new_file"
cp "$sql_file" "$new_file"
fi
done < git_tags.txt
else
echo "Warning: $sql_file not found"
fi
rm git_tags.txt
'';
postInstall = ''
echo "Modifying main SQL file to use unversioned library name..."
current_version="${version}"
main_sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"
if [ -f "$main_sql_file" ]; then
sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$main_sql_file"
echo "Modified $main_sql_file"
else
echo "Warning: $main_sql_file not found"
fi
echo "Creating and modifying SQL files for previous versions..."

if [ -f "$main_sql_file" ]; then
while read -r previous_version; do
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql"
echo "Creating $new_file"
cp "$main_sql_file" "$new_file"
sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$new_file"
echo "Modified $new_file"
fi
done < git_tags.txt
else
echo "Warning: $main_sql_file not found"
fi
mv $out/lib/wrappers-${version}.so $out/lib/wrappers.so

echo "Creating wrappers.so symlinks to support pg_upgrade..."
if [ -f "$out/lib/wrappers.so" ]; then
while read -r previous_version; do
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
new_file="$out/lib/wrappers-$previous_version.so"
echo "Creating $new_file"
ln -s "$out/lib/wrappers.so" "$new_file"
fi
done < git_tags.txt
else
echo "Warning: $out/lib/wrappers.so not found"
fi

rm git_tags.txt
echo "Contents of updated wrappers.control:"
cat "$out/share/postgresql/extension/wrappers.control"
echo "List of generated SQL files:"
ls -l $out/share/postgresql/extension/wrappers--*.sql
'';

meta = with lib; {
description = "Various Foreign Data Wrappers (FDWs) for PostreSQL";
Expand Down
Loading