Commit a0d3dff
committed
fix(postgresql): place deb-extracted binaries at lib/postgresql/<major>/bin so PG can relocate sharedir
Closes #112.
PostgreSQL's deb packages are compiled with the unusual split layout
BINDIR=/usr/lib/postgresql/<major>/bin, SHAREDIR=/usr/share/postgresql/<major>.
At runtime PG uses make_relative_path() (src/port/path.c) to relocate
SHAREDIR (and PKGLIBDIR) relative to the running binary, but only if
the binary's parent directory matches the bin_path tail after stripping
the common prefix with target_path. For these compiled-in paths the
common prefix is just "/usr/", so the binary's parent must end in
"lib/postgresql/<major>/bin".
dbdeployer previously placed the binaries at <basedir>/bin/, so the tail
match failed and PG fell back to the absolute compiled-in path
"/usr/share/postgresql/<major>" — which doesn't exist on a clean machine
without postgresql-common installed. initdb then died with:
FATAL: could not open directory "/usr/share/postgresql/16/timezonesets"
The existing code already double-copied share into both
<basedir>/share/ (for `initdb -L`) and <basedir>/share/postgresql/<major>/
(for runtime relocation) — half the puzzle. The missing half was the
binary placement.
Changes in providers/postgresql/unpack.go:
- Real binaries go to <basedir>/lib/postgresql/<major>/bin/
- Extension libs (PKGLIBDIR) go to <basedir>/lib/postgresql/<major>/lib/
- <basedir>/bin/<binary> are now relative symlinks into the nested bin/.
On Linux find_my_exec() reads /proc/self/exe which resolves symlinks
to the real file, so launching via the symlink still gives PG the
relocatable path it needs. Existing callers (sandbox.go, scripts.go)
reach binaries via <basedir>/bin/ as before — no API change.
- UnpackDebs is now idempotent: it removes any prior bin/, lib/, share/
artifacts before recreating them, so users can re-run unpack to migrate
from the old (broken) layout to the new one without a separate flag.
Changes in providers/postgresql/sandbox.go:
- New checkLinuxLayout() runs at the top of CreateSandbox. If it finds
<basedir>/bin/postgres is a regular file (rather than the new symlink)
on Linux, it returns an error pointing the user at `dbdeployer unpack`
to fix the layout. This replaces the cryptic
"/usr/share/postgresql/16/timezonesets" error with an actionable one.
- macOS path is unchanged. Postgres.app's PG is compiled with the
standard --prefix layout where BINDIR=<prefix>/bin and
SHAREDIR=<prefix>/share/postgresql, so the common prefix covers the
whole <prefix>/ and the bin tail is just "bin" — which dbdeployer's
<basedir>/bin/ already satisfies.
Manually verified end-to-end on a clean Ubuntu 24.04-like environment
with `apt-get download postgresql-16 postgresql-client-16 && dbdeployer
unpack --provider=postgresql ... && dbdeployer deploy postgresql 16.13`.
Initdb succeeds, sandbox starts, SELECT version() returns the expected
build, clean shutdown. Old-layout detection also verified by copying a
regular file over the symlink and confirming the deploy fails with the
new actionable message. The CI integration test currently masks this
bug by installing postgresql-16 system-wide before unpacking — a
follow-up PR will switch CI to `apt-get download` only.1 parent 857149f commit a0d3dff
2 files changed
Lines changed: 86 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
23 | 28 | | |
24 | 29 | | |
25 | 30 | | |
| |||
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
72 | 88 | | |
73 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
74 | 100 | | |
75 | 101 | | |
76 | 102 | | |
77 | 103 | | |
78 | 104 | | |
79 | 105 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
83 | 110 | | |
84 | 111 | | |
85 | 112 | | |
| |||
91 | 118 | | |
92 | 119 | | |
93 | 120 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
101 | 126 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
105 | 136 | | |
106 | 137 | | |
107 | 138 | | |
| |||
0 commit comments