Skip to content

Commit 37e8528

Browse files
samrosejfroche
andauthored
feat: multi version pg_net including 0.19.5 (#1744)
* feat: multi version pg_net including 0.19.5 * feat: bump ver and add tests * feat: if file exists, run prestart version switch scripts * tests: bump version to test * fix: rm unneeded check and fix err codes for file handling * chore: bump version for testing * chore: update versions for release * Add pg-net nixos test in flake checks output * Move switch_pg_net_version script into separate package * Fix shellcheck errors * feat: limit using verison in extension creation to admin user for all extensions by using supautils and before-create hooks add test for this in pg_net * feat(pg_net): switch version on file system using overlayfs For pg_net background worker, we need to switch the version of the extension on the file system (both pg_net.so and pg_net.control need to point to the desired version). As the extension is in the Nix store, we cannot simply symlink to the desired version, as the Nix store is read-only. To work around this, we use overlayfs to create a writable layer on top of the pg_net store path. * Revert "feat:" This reverts commit 268cadb. * fix: fmt * chore: bump version for testin * fix: control files need module_pathname * Revert "fix: control files need module_pathname" This reverts commit 4996d81. This change would not resolve the issue it was targeting. * chore: version bump for testing * fix: limit flag to versions less than 0.19.1 * chore: bump version for release --------- Co-authored-by: Jean-François Roche <[email protected]>
1 parent 88247a3 commit 37e8528

File tree

10 files changed

+565
-36
lines changed

10 files changed

+565
-36
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ result*
1919
.history
2020
.envrc
2121
.direnv
22-
22+
.nixos-test-history
2323

2424
#IDE
2525
.idea/
@@ -30,3 +30,4 @@ common-nix.vars.pkr.hcl
3030

3131
# pre-commit config is managed in nix
3232
.pre-commit-config.yaml
33+
nixos.qcow2

ansible/files/postgres_prestart.sh.j2

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
set -x # Print commands
4+
5+
log() {
6+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
7+
}
8+
39
check_orioledb_enabled() {
410
local pg_conf="/etc/postgresql/postgresql.conf"
511
if [ ! -f "$pg_conf" ]; then
@@ -26,7 +32,87 @@ update_orioledb_buffers() {
2632
fi
2733
}
2834

35+
check_extensions_file() {
36+
local extensions_file="/etc/adminapi/pg-extensions.json"
37+
if [ ! -f "$extensions_file" ]; then
38+
log "extensions: No extensions file found, skipping extensions versions check"
39+
return 0 #if file not found, skip
40+
fi
41+
if [ ! -r "$extensions_file" ]; then
42+
log "extensions: Cannot read extensions file"
43+
return 1 #a true error, we should be able to read file
44+
fi
45+
return 0
46+
}
47+
48+
switch_extension_version() {
49+
local extension_name="$1"
50+
local version="$2"
51+
52+
# Use BIN_PATH environment variable or default to /var/lib/postgresql/.nix-profile
53+
: ${BIN_PATH:="/var/lib/postgresql/.nix-profile"}
54+
55+
local switch_script="$BIN_PATH/bin/switch_${extension_name}_version"
56+
57+
if [ ! -x "$switch_script" ]; then
58+
log "$extension_name: No version switch script available at $switch_script, skipping"
59+
return 0
60+
fi
61+
62+
log "$extension_name: Switching to version $version"
63+
# Run directly as root since we're already running as root
64+
"$switch_script" "$version"
65+
local exit_code=$?
66+
if [ $exit_code -eq 0 ]; then
67+
log "$extension_name: Version switch completed successfully"
68+
else
69+
log "$extension_name: Version switch failed with exit code $exit_code"
70+
fi
71+
return $exit_code
72+
}
73+
74+
handle_extension_versions() {
75+
if ! check_extensions_file; then
76+
return
77+
fi
78+
79+
local extensions_file="/etc/adminapi/pg-extensions.json"
80+
81+
# Get all extension names from the JSON file
82+
local extensions
83+
extensions=$(jq -r 'keys[]' "$extensions_file" 2>/dev/null)
84+
85+
if [ -z "$extensions" ]; then
86+
log "extensions: No extensions found in configuration"
87+
return
88+
fi
89+
90+
# Iterate through each extension
91+
while IFS= read -r extension_name; do
92+
# Get the version for this extension
93+
local version
94+
version=$(jq -r --arg ext "$extension_name" '.[$ext] // empty' "$extensions_file")
95+
96+
if [ -z "$version" ]; then
97+
log "$extension_name: No version specified, skipping"
98+
continue
99+
fi
100+
101+
log "$extension_name: Found version $version in extensions file"
102+
103+
# Don't fail if version switch fails - just log and continue
104+
switch_extension_version "$extension_name" "$version" || log "$extension_name: Version switch failed but continuing"
105+
106+
done <<< "$extensions"
107+
}
108+
29109
main() {
110+
log "Starting prestart script"
111+
112+
# 1. Handle all extension versions from config file
113+
handle_extension_versions
114+
115+
# 2. orioledb handling
30116
local has_orioledb=$(check_orioledb_enabled)
31117
if [ "$has_orioledb" -lt 1 ]; then
32118
return 0
@@ -35,6 +121,8 @@ main() {
35121
if [ ! -z "$shared_buffers_value" ]; then
36122
update_orioledb_buffers "$shared_buffers_value"
37123
fi
124+
125+
log "Prestart script completed"
38126
}
39127

40128
# Initial locale setup
@@ -46,4 +134,4 @@ if [ $(locale -a | grep -c en_US.utf8) -eq 0 ]; then
46134
locale-gen
47135
fi
48136

49-
main
137+
main

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ postgres_major:
99

1010
# Full version strings for each major version
1111
postgres_release:
12-
postgresorioledb-17: "17.5.1.017-orioledb"
13-
postgres17: "17.4.1.074"
14-
postgres15: "15.8.1.131"
12+
postgresorioledb-17: "17.5.1.018-orioledb"
13+
postgres17: "17.4.1.075"
14+
postgres15: "15.8.1.132"
1515

1616
# Non Postgres Extensions
1717
pgbouncer_release: "1.19.0"

nix/checks.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@
309309
;
310310
}
311311
// pkgs.lib.optionalAttrs (system == "x86_64-linux") {
312+
pg_net = import ./ext/tests/pg_net.nix {
313+
inherit self;
314+
inherit pkgs;
315+
};
312316
wrappers = import ./ext/tests/wrappers.nix {
313317
inherit self;
314318
inherit pkgs;

0 commit comments

Comments
 (0)