Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 40 additions & 1 deletion Dockerfile-multigres
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ RUN sed -i \
-e "s|#unix_socket_directories = '/tmp'|unix_socket_directories = '/var/run/postgresql'|g" \
-e "s|#session_preload_libraries = ''|session_preload_libraries = 'supautils'|g" \
-e "s|#include = '/etc/postgresql-custom/supautils.conf'|include = '/etc/postgresql-custom/supautils.conf'|g" \
-e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \
# skip wal-g - unused by multigres
# -e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" \
-e "s/ timescaledb,//g" \
-e "s/ pgsodium,//g" \
-e "s/db_user_namespace = off/#db_user_namespace = off/g" \
# skip - managed by pgctld
-e "s|^data_directory |#data_directory |g" \
/etc/postgresql/postgresql.conf && \
echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
Expand Down Expand Up @@ -203,6 +206,25 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres-
# Strip extensions absent from pg17 vanilla build
RUN sed -i 's/ timescaledb,//g; s/ plv8,//g' /etc/postgresql-custom/supautils.conf

# Generate a single SQL manifest that pgctld runs via --init-db-sql-file after initdb.
# Creates the postgres role, runs init-scripts as postgres (matching migrate.sh),
# then runs migrations as supabase_admin.
RUN set -e && \
manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \
printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \
printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \
printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \
printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \
for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \
printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \
done && \
printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \
for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \
printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \
done && \
chown postgres:postgres "$manifest"

ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql
ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}"
ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive

Expand Down Expand Up @@ -267,6 +289,23 @@ RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres-
> /usr/local/bin/pgctld && \
chmod +x /usr/local/bin/pgctld

# Regenerate manifest after orioledb added 00-pre-init.sql to init-scripts/
RUN set -e && \
manifest=/docker-entrypoint-initdb.d/multigres-init.sql && \
printf -- "-- Auto-generated: run init-scripts and migrations after initdb\n" > "$manifest" && \
printf "DO \$\$ BEGIN\n IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'postgres') THEN\n CREATE ROLE postgres SUPERUSER LOGIN;\n END IF;\nEND \$\$;\n" >> "$manifest" && \
printf "ALTER DATABASE postgres OWNER TO postgres;\n\n" >> "$manifest" && \
printf "SET SESSION AUTHORIZATION postgres;\n" >> "$manifest" && \
for f in $(ls /docker-entrypoint-initdb.d/init-scripts/*.sql 2>/dev/null | sort); do \
printf '\\ir init-scripts/%s\n' "$(basename "$f")" >> "$manifest"; \
done && \
printf "\nRESET SESSION AUTHORIZATION;\n\n" >> "$manifest" && \
for f in $(ls /docker-entrypoint-initdb.d/migrations/*.sql 2>/dev/null | sort); do \
printf '\\ir migrations/%s\n' "$(basename "$f")" >> "$manifest"; \
done && \
chown postgres:postgres "$manifest"

ENV POSTGRES_INITDB_SQL_FILES=/docker-entrypoint-initdb.d/multigres-init.sql
ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}"
ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive

Expand Down
6 changes: 3 additions & 3 deletions ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ postgres_major:

# Full version strings for each major version
postgres_release:
postgresorioledb-17: "17.6.0.072-orioledb"
postgres17: "17.6.1.115"
postgres15: "15.14.1.115"
postgresorioledb-17: "17.6.0.074-orioledb"
postgres17: "17.6.1.117"
postgres15: "15.14.1.117"

# Non Postgres Extensions
pgbouncer_release: 1.25.1
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions nix/packages/docker-image-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ writeShellApplication {

# 3. pgctld init must succeed with no extra flags (tests USER postgres fix)
local init_out
init_out=$(docker exec "$container" sh -c "/usr/local/bin/pgctld init --pooler-dir $pooler_dir 2>&1")
init_out=$(docker exec -e PGDATA="$pooler_dir/pg_data" "$container" sh -c "/usr/local/bin/pgctld init --pooler-dir $pooler_dir 2>&1")
if ! echo "$init_out" | grep -q "initialized successfully"; then
log_error " pgctld init failed: $init_out"
exit 1
Expand All @@ -330,7 +330,7 @@ writeShellApplication {

# 4. pgctld start must succeed
local start_out
start_out=$(docker exec "$container" sh -c "/usr/local/bin/pgctld start --pooler-dir $pooler_dir 2>&1")
start_out=$(docker exec -e PGDATA="$pooler_dir/pg_data" "$container" sh -c "/usr/local/bin/pgctld start --pooler-dir $pooler_dir 2>&1")
if ! echo "$start_out" | grep -q "started successfully"; then
log_error " pgctld start failed: $start_out"
exit 1
Expand Down Expand Up @@ -398,7 +398,9 @@ writeShellApplication {

log_info "Multigres: starting PostgreSQL (config at /etc/postgresql)..."
docker exec -u postgres "$container" \
pg_ctl start -D /etc/postgresql -w -t 60
pg_ctl start -D /var/lib/postgresql/data \
-o "-c config_file=/etc/postgresql/postgresql.conf" \
-w -t 60

log_info "Multigres: running schema migrations..."
docker exec \
Expand Down
2 changes: 1 addition & 1 deletion nix/packages/pgctld.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildGoModule {
'';
# Tests require a running PostgreSQL instance (integration tests); skip in sandbox.
doCheck = false;
vendorHash = "sha256-cqSd6Dv0WYOVwg7AE1tZPh9uzsjDG32gF6eJzARsHo8=";
vendorHash = "sha256-P+B5fDlCdL0gxUa96BXz+1D0+6RSlul8eMv7iEI3Lpo=";

meta = {
description = "PostgreSQL control daemon for Multigres cluster lifecycle management";
Expand Down
Loading