@@ -292,6 +292,92 @@ writeShellApplication {
292292 return 1
293293 }
294294
295+ # Verify pgctld integration for multigres images.
296+ # Runs a short-lived pgctld cluster in /tmp (separate from the SQL-test postgres).
297+ # Tests: container user is postgres, /usr/local/bin/pgctld works, pgctld init+start
298+ # succeeds with NO extra flags, and (orioledb variant) orioledb loads automatically.
299+ verify_pgctld_integration() {
300+ local container="$1"
301+ local version="$2"
302+ local pooler_dir="/tmp/pgctld-verify"
303+
304+ log_info "=== pgctld integration checks ==="
305+
306+ # 1. Container must run as postgres (not root) — initdb refuses root
307+ local container_user
308+ container_user=$(docker exec "$container" id -u -n)
309+ if [[ "$container_user" != "postgres" ]]; then
310+ log_error "Container user is '$container_user', expected 'postgres' — USER directive missing"
311+ exit 1
312+ fi
313+ log_info " ✓ container user: $container_user"
314+
315+ # 2. /usr/local/bin/pgctld must exist (k8s manifest hardcodes this path)
316+ if ! docker exec "$container" test -e /usr/local/bin/pgctld; then
317+ log_error " /usr/local/bin/pgctld not found"
318+ exit 1
319+ fi
320+ log_info " ✓ /usr/local/bin/pgctld exists"
321+
322+ # 3. pgctld init must succeed with no extra flags (tests USER postgres fix)
323+ local init_out
324+ init_out=$(docker exec "$container" sh -c "/usr/local/bin/pgctld init --pooler-dir $pooler_dir 2>&1")
325+ if ! echo "$init_out" | grep -q "initialized successfully"; then
326+ log_error " pgctld init failed: $init_out"
327+ exit 1
328+ fi
329+ log_info " ✓ pgctld init --pooler-dir $pooler_dir"
330+
331+ # 4. pgctld start must succeed
332+ local start_out
333+ start_out=$(docker exec "$container" sh -c "/usr/local/bin/pgctld start --pooler-dir $pooler_dir 2>&1")
334+ if ! echo "$start_out" | grep -q "started successfully"; then
335+ log_error " pgctld start failed: $start_out"
336+ exit 1
337+ fi
338+ log_info " ✓ pgctld start --pooler-dir $pooler_dir"
339+
340+ if [[ "$version" == "multigres-orioledb-17" ]]; then
341+ # 5. /usr/local/bin/pgctld must be a wrapper script (not a plain symlink)
342+ local first_line
343+ first_line=$(docker exec "$container" sh -c "head -1 /usr/local/bin/pgctld")
344+ if [[ "$first_line" != "#!/bin/sh" ]]; then
345+ log_error " /usr/local/bin/pgctld is not a wrapper script (first line: $first_line)"
346+ exit 1
347+ fi
348+ log_info " ✓ /usr/local/bin/pgctld is a wrapper script"
349+
350+ # 6. shared_preload_libraries must include orioledb — injected by wrapper, no flags needed
351+ local spl
352+ spl=$(docker exec "$container" sh -c "
353+ psql -U postgres -h $pooler_dir/pg_sockets \
354+ -tAc \"SHOW shared_preload_libraries;\" 2>&1")
355+ if ! echo "$spl" | grep -q "orioledb"; then
356+ log_error " orioledb not in shared_preload_libraries (got: $spl)"
357+ log_error " Check that wrapper script injects --postgres-config-template"
358+ exit 1
359+ fi
360+ log_info " ✓ shared_preload_libraries contains orioledb"
361+
362+ # 7. default_table_access_method must be orioledb
363+ local tam
364+ tam=$(docker exec "$container" sh -c "
365+ psql -U postgres -h $pooler_dir/pg_sockets \
366+ -tAc \"SHOW default_table_access_method;\" 2>&1")
367+ if ! echo "$tam" | grep -q "orioledb"; then
368+ log_error " default_table_access_method is not orioledb (got: $tam)"
369+ exit 1
370+ fi
371+ log_info " ✓ default_table_access_method = orioledb"
372+ fi
373+
374+ # Shut down the pgctld test cluster so it doesn't hold the unix socket
375+ docker exec "$container" sh -c "
376+ pg_ctl stop -D $pooler_dir/pg_data -m immediate 2>/dev/null || true
377+ "
378+ log_info "=== pgctld integration checks passed ==="
379+ }
380+
295381 # Bootstrap a multigres container: initdb + pg_ctl start + create supabase_admin + run migrations
296382 # Multigres images use "tail -f /dev/null" as entrypoint so postgres must be started manually.
297383 start_multigres_postgres() {
@@ -408,6 +494,7 @@ writeShellApplication {
408494 # Multigres images use "tail -f /dev/null" as their entrypoint — postgres must be
409495 # started manually before we can run tests against them.
410496 if [[ "$VERSION" == multigres-* ]]; then
497+ verify_pgctld_integration "$CONTAINER_NAME" "$VERSION"
411498 start_multigres_postgres "$CONTAINER_NAME"
412499 fi
413500
0 commit comments