Skip to content

Commit 0c52b1f

Browse files
pcncsoedirgokangmingtayhfsamrose
authored
chore: add timescaledb 2.9.1; wrappers upgrade fix; wrappers & plv8 naming fix (#1259)
Co-authored-by: Bobbie Soedirgo <[email protected]> Co-authored-by: Bobbie Soedirgo <[email protected]> Co-authored-by: Kang Ming <[email protected]> Co-authored-by: Stojan Dimitrovski <[email protected]> Co-authored-by: Sam Rose <[email protected]> fix(ci): respect postgresVersion input (#1237) fix: only grant pg_read_all_data if it exists (#1242) fix(15.6): disable pg_stat_monitor (#1260)
1 parent 9062da4 commit 0c52b1f

File tree

5 files changed

+108
-79
lines changed

5 files changed

+108
-79
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")
4747

4848
POSTGRES_CONFIG_PATH="/etc/postgresql/postgresql.conf"
4949
PGBINOLD="/usr/lib/postgresql/bin"
50-
PGLIBOLD="/usr/lib/postgresql/lib"
5150

5251
PG_UPGRADE_BIN_DIR="/tmp/pg_upgrade_bin/$PGVERSION"
5352
NIX_INSTALLER_PATH="/tmp/persistent/nix-installer"
@@ -181,58 +180,6 @@ EOF
181180
done
182181
}
183182

184-
function patch_wrappers {
185-
local IS_NIX_UPGRADE=$1
186-
187-
WRAPPERS_ENABLED=$(run_sql -A -t -c "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'wrappers');")
188-
if [ "$WRAPPERS_ENABLED" = "f" ]; then
189-
echo "Wrappers extension not enabled. Skipping."
190-
return
191-
fi
192-
193-
# This is a workaround for older versions of wrappers which don't have the expected
194-
# naming scheme, containing the version in their library's file name
195-
# e.g. wrappers-0.1.16.so, rather than wrappers.so
196-
# pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's
197-
# library directory, so we're making sure the new version has the expected (old version's)
198-
# file name.
199-
# After the upgrade completes, the new version's library file is used.
200-
# i.e.
201-
# - old version: wrappers-0.1.16.so
202-
# - new version: wrappers-0.1.18.so
203-
# - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so
204-
if [ "$IS_NIX_UPGRADE" = "true" ]; then
205-
if [ -d "$PGLIBOLD" ]; then
206-
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
207-
OLD_LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
208-
209-
find /nix/store/ -name "wrappers*so" -print0 | while read -r -d $'\0' WRAPPERS_LIB_PATH; do
210-
if [ -f "$WRAPPERS_LIB_PATH" ]; then
211-
WRAPPERS_LIB_PATH_DIR=$(dirname "$WRAPPERS_LIB_PATH")
212-
if [ "$WRAPPERS_LIB_PATH" != "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" ]; then
213-
echo "Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}"
214-
cp "$WRAPPERS_LIB_PATH" "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" || true
215-
fi
216-
fi
217-
done
218-
fi
219-
else
220-
if [ -d "$PGLIBOLD" ]; then
221-
WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit)
222-
if [ -f "$WRAPPERS_LIB_PATH" ]; then
223-
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
224-
if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then
225-
LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
226-
if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then
227-
echo "Copying $WRAPPERS_LIB_PATH to $PGLIBNEW/${LIB_FILE_NAME}"
228-
cp "$WRAPPERS_LIB_PATH" "$PGLIBNEW/${LIB_FILE_NAME}" || true
229-
fi
230-
fi
231-
fi
232-
fi
233-
fi
234-
}
235-
236183
function initiate_upgrade {
237184
mkdir -p "$MOUNT_POINT"
238185
SHARED_PRELOAD_LIBRARIES=$(cat "$POSTGRES_CONFIG_PATH" | grep shared_preload_libraries | sed "s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/")
@@ -409,8 +356,6 @@ function initiate_upgrade {
409356
export LD_LIBRARY_PATH="${PGLIBNEW}"
410357
fi
411358

412-
patch_wrappers "$IS_NIX_UPGRADE"
413-
414359
echo "9. Creating new data directory, initializing database"
415360
chown -R postgres:postgres "$MOUNT_POINT/"
416361
rm -rf "${PGDATANEW:?}/"

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
ourExtensions = [
108108
./nix/ext/rum.nix
109109
./nix/ext/timescaledb.nix
110+
./nix/ext/timescaledb-2.9.1.nix
110111
./nix/ext/pgroonga.nix
111112
./nix/ext/index_advisor.nix
112113
./nix/ext/wal2json.nix

nix/ext/plv8.nix

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,20 @@ stdenv.mkDerivation (finalAttrs: {
103103
# so changing them does not cause issues.
104104
mv "$out/nix/store"/*/* "$out"
105105
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
106-
106+
mv "$out/lib/plv8-${finalAttrs.version}.so" "$out/lib/plv8.so"
107+
ln -s "$out/lib/plv8.so" "$out/lib/plv8-${finalAttrs.version}.so"
108+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plv8.control"
109+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plcoffee.control"
110+
sed -i 's|module_pathname = '"'"'$libdir/plv8-[0-9.]*'"'"'|module_pathname = '"'"'$libdir/plv8'"'"'|' "$out/share/postgresql/extension/plls.control"
107111
${lib.optionalString stdenv.isDarwin ''
108-
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8-${finalAttrs.version}.so
109-
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8-${finalAttrs.version}.so
110-
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
111-
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8-${finalAttrs.version}.so
112+
install_name_tool -add_rpath "${v8}/lib" $out/lib/plv8.so
113+
install_name_tool -add_rpath "${postgresql}/lib" $out/lib/plv8.so
114+
install_name_tool -add_rpath "${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
115+
install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/plv8.so
112116
''}
113117
114118
${lib.optionalString (!stdenv.isDarwin) ''
115-
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8-${finalAttrs.version}.so
119+
${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${stdenv.cc.cc.lib}/lib" $out/lib/plv8.so
116120
''}
117121
'';
118122

nix/ext/timescaledb-2.9.1.nix

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{ lib, stdenv, fetchFromGitHub, cmake, postgresql, openssl, libkrb5 }:
2+
3+
stdenv.mkDerivation rec {
4+
pname = "timescaledb-apache";
5+
version = "2.9.1";
6+
7+
nativeBuildInputs = [ cmake ];
8+
buildInputs = [ postgresql openssl libkrb5 ];
9+
10+
src = fetchFromGitHub {
11+
owner = "timescale";
12+
repo = "timescaledb";
13+
rev = version;
14+
hash = "sha256-fvVSxDiGZAewyuQ2vZDb0I6tmlDXl6trjZp8+qDBtb8=";
15+
};
16+
17+
cmakeFlags = [ "-DSEND_TELEMETRY_DEFAULT=OFF" "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=1" ]
18+
++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ];
19+
20+
# Fix the install phase which tries to install into the pgsql extension dir,
21+
# and cannot be manually overridden. This is rather fragile but works OK.
22+
postPatch = ''
23+
for x in CMakeLists.txt sql/CMakeLists.txt; do
24+
substituteInPlace "$x" \
25+
--replace 'DESTINATION "''${PG_SHAREDIR}/extension"' "DESTINATION \"$out/share/postgresql/extension\""
26+
done
27+
28+
for x in src/CMakeLists.txt src/loader/CMakeLists.txt tsl/src/CMakeLists.txt; do
29+
substituteInPlace "$x" \
30+
--replace 'DESTINATION ''${PG_PKGLIBDIR}' "DESTINATION \"$out/lib\""
31+
done
32+
'';
33+
34+
35+
# timescaledb-2.9.1.so already exists in the lib directory
36+
# we have no need for the timescaledb.so or control file
37+
postInstall = ''
38+
rm $out/lib/timescaledb.so
39+
rm $out/share/postgresql/extension/timescaledb.control
40+
'';
41+
42+
meta = with lib; {
43+
description = "Scales PostgreSQL for time-series data via automatic partitioning across time and space";
44+
homepage = "https://www.timescale.com/";
45+
changelog = "https://github.com/timescale/timescaledb/blob/${version}/CHANGELOG.md";
46+
maintainers = with maintainers; [ samrose ];
47+
platforms = postgresql.meta.platforms;
48+
license = licenses.asl20;
49+
broken = versionOlder postgresql.version "13";
50+
};
51+
}

nix/ext/wrappers/default.nix

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,52 @@ buildPgrxExtension_0_11_3 rec {
6363
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
6464
'';
6565

66-
postInstall = ''
67-
echo "Creating SQL files for previous versions..."
68-
current_version="${version}"
69-
sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"
70-
71-
if [ -f "$sql_file" ]; then
72-
while read -r previous_version; do
73-
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
74-
new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql"
75-
echo "Creating $new_file"
76-
cp "$sql_file" "$new_file"
77-
fi
78-
done < git_tags.txt
79-
else
80-
echo "Warning: $sql_file not found"
81-
fi
82-
rm git_tags.txt
83-
'';
66+
postInstall = ''
67+
echo "Modifying main SQL file to use unversioned library name..."
68+
current_version="${version}"
69+
main_sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"
70+
if [ -f "$main_sql_file" ]; then
71+
sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$main_sql_file"
72+
echo "Modified $main_sql_file"
73+
else
74+
echo "Warning: $main_sql_file not found"
75+
fi
76+
echo "Creating and modifying SQL files for previous versions..."
77+
78+
if [ -f "$main_sql_file" ]; then
79+
while read -r previous_version; do
80+
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
81+
new_file="$out/share/postgresql/extension/wrappers--$previous_version--$current_version.sql"
82+
echo "Creating $new_file"
83+
cp "$main_sql_file" "$new_file"
84+
sed -i 's|$libdir/wrappers-[0-9.]*|$libdir/wrappers|g' "$new_file"
85+
echo "Modified $new_file"
86+
fi
87+
done < git_tags.txt
88+
else
89+
echo "Warning: $main_sql_file not found"
90+
fi
91+
mv $out/lib/wrappers-${version}.so $out/lib/wrappers.so
92+
93+
echo "Creating wrappers.so symlinks to support pg_upgrade..."
94+
if [ -f "$out/lib/wrappers.so" ]; then
95+
while read -r previous_version; do
96+
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
97+
new_file="$out/lib/wrappers-$previous_version.so"
98+
echo "Creating $new_file"
99+
ln -s "$out/lib/wrappers.so" "$new_file"
100+
fi
101+
done < git_tags.txt
102+
else
103+
echo "Warning: $out/lib/wrappers.so not found"
104+
fi
105+
106+
rm git_tags.txt
107+
echo "Contents of updated wrappers.control:"
108+
cat "$out/share/postgresql/extension/wrappers.control"
109+
echo "List of generated SQL files:"
110+
ls -l $out/share/postgresql/extension/wrappers--*.sql
111+
'';
84112

85113
meta = with lib; {
86114
description = "Various Foreign Data Wrappers (FDWs) for PostreSQL";

0 commit comments

Comments
 (0)