Skip to content

Commit 8b68211

Browse files
committed
feat: supporting postgres 18rc1
1 parent 45c29b7 commit 8b68211

File tree

14 files changed

+342
-31
lines changed

14 files changed

+342
-31
lines changed

Dockerfile-18

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
# syntax=docker/dockerfile:1.6
2+
ARG postgresql_major=18
3+
ARG postgresql_release=${postgresql_major}.0
4+
5+
# Bump default build arg to build a package from source
6+
# Bump vars.yml to specify runtime package version
7+
ARG sfcgal_release=1.3.10
8+
ARG postgis_release=3.3.2
9+
ARG pgrouting_release=3.4.1
10+
ARG pgtap_release=1.2.0
11+
ARG pg_cron_release=1.6.7
12+
ARG pgaudit_release=1.7.0
13+
ARG pgjwt_release=9742dab1b2f297ad3811120db7b21451bca2d3c9
14+
ARG pgsql_http_release=1.5.0
15+
ARG plpgsql_check_release=2.2.5
16+
ARG pg_safeupdate_release=1.4
17+
ARG timescaledb_release=2.9.1
18+
ARG wal2json_release=2_5
19+
ARG pljava_release=1.6.4
20+
ARG plv8_release=3.1.5
21+
ARG pg_plan_filter_release=5081a7b5cb890876e67d8e7486b6a64c38c9a492
22+
ARG pg_net_release=0.7.1
23+
ARG rum_release=1.3.13
24+
ARG pg_hashids_release=cd0e1b31d52b394a0df64079406a14a4f7387cd6
25+
ARG libsodium_release=1.0.18
26+
ARG pgsodium_release=3.1.6
27+
ARG pg_graphql_release=1.5.11
28+
ARG pg_stat_monitor_release=1.1.1
29+
ARG pg_jsonschema_release=0.1.4
30+
ARG pg_repack_release=1.4.8
31+
ARG vault_release=0.2.8
32+
ARG groonga_release=12.0.8
33+
ARG pgroonga_release=2.4.0
34+
ARG wrappers_release=0.5.4
35+
ARG hypopg_release=1.3.1
36+
ARG pgvector_release=0.4.0
37+
ARG pg_tle_release=1.3.2
38+
ARG index_advisor_release=0.2.0
39+
ARG supautils_release=2.2.0
40+
ARG wal_g_release=3.0.5
41+
42+
FROM ubuntu:noble as base
43+
44+
RUN apt update -y && apt install -y \
45+
curl \
46+
gnupg \
47+
lsb-release \
48+
software-properties-common \
49+
wget \
50+
sudo \
51+
tree \
52+
&& apt clean
53+
54+
55+
RUN adduser --system --home /var/lib/postgresql --no-create-home --shell /bin/bash --group --gecos "PostgreSQL administrator" postgres
56+
RUN adduser --system --no-create-home --shell /bin/bash --group wal-g
57+
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux \
58+
--init none \
59+
--no-confirm \
60+
--extra-conf "substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com" \
61+
--extra-conf "trusted-public-keys = nix-postgres-artifacts:dGZlQOvKcNEjvT7QEAJbcV6b6uk7VF/hWMjhYleiaLI=% cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
62+
63+
ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin"
64+
65+
COPY . /nixpg
66+
67+
WORKDIR /nixpg
68+
69+
RUN nix profile install .#psql_18/bin
70+
71+
RUN nix store gc
72+
73+
WORKDIR /
74+
75+
76+
RUN mkdir -p /usr/lib/postgresql/bin \
77+
/usr/lib/postgresql/share/postgresql \
78+
/usr/share/postgresql \
79+
/var/lib/postgresql \
80+
&& chown -R postgres:postgres /usr/lib/postgresql \
81+
&& chown -R postgres:postgres /var/lib/postgresql \
82+
&& chown -R postgres:postgres /usr/share/postgresql
83+
84+
# Create symbolic links
85+
RUN ln -s /nix/var/nix/profiles/default/bin/* /usr/lib/postgresql/bin/ \
86+
&& ln -s /nix/var/nix/profiles/default/bin/* /usr/bin/ \
87+
&& chown -R postgres:postgres /usr/bin
88+
89+
# Create symbolic links for PostgreSQL shares
90+
RUN ln -s /nix/var/nix/profiles/default/share/postgresql/* /usr/lib/postgresql/share/postgresql/
91+
RUN ln -s /nix/var/nix/profiles/default/share/postgresql/* /usr/share/postgresql/
92+
RUN chown -R postgres:postgres /usr/lib/postgresql/share/postgresql/
93+
RUN chown -R postgres:postgres /usr/share/postgresql/
94+
# Create symbolic links for contrib directory
95+
RUN tree /nix > /tmp/tree.txt && cat /tmp/tree.txt && cat /tmp/tree.txt >&2
96+
97+
RUN chown -R postgres:postgres /usr/lib/postgresql
98+
99+
RUN ln -sf /usr/lib/postgresql/share/postgresql/timezonesets /usr/share/postgresql/timezonesets
100+
101+
102+
RUN apt-get update && \
103+
apt-get install -y --no-install-recommends tzdata
104+
105+
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
106+
dpkg-reconfigure --frontend noninteractive tzdata
107+
108+
RUN apt-get update && \
109+
apt-get install -y --no-install-recommends \
110+
build-essential \
111+
checkinstall \
112+
cmake
113+
114+
ENV PGDATA=/var/lib/postgresql/data
115+
116+
####################
117+
# setup-wal-g.yml
118+
####################
119+
FROM base as walg
120+
ARG wal_g_release
121+
122+
WORKDIR /nixpg
123+
124+
RUN nix profile install .#wal-g-3 && \
125+
ln -s /nix/var/nix/profiles/default/bin/wal-g-3 /tmp/wal-g
126+
127+
RUN nix store gc
128+
129+
WORKDIR /
130+
# ####################
131+
# # Download gosu for easy step-down from root
132+
# ####################
133+
FROM base as gosu
134+
ARG TARGETARCH
135+
# Install dependencies
136+
RUN apt-get update && apt-get install -y --no-install-recommends \
137+
gnupg \
138+
ca-certificates \
139+
&& rm -rf /var/lib/apt/lists/*
140+
# Download binary
141+
ARG GOSU_VERSION=1.16
142+
ARG GOSU_GPG_KEY=B42F6819007F00F88E364FD4036A9C25BF357DD4
143+
ADD https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH \
144+
/usr/local/bin/gosu
145+
ADD https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH.asc \
146+
/usr/local/bin/gosu.asc
147+
# Verify checksum
148+
RUN gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys $GOSU_GPG_KEY && \
149+
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu && \
150+
gpgconf --kill all && \
151+
chmod +x /usr/local/bin/gosu
152+
153+
# ####################
154+
# # Build final image
155+
# ####################
156+
FROM gosu as production
157+
RUN id postgres || (echo "postgres user does not exist" && exit 1)
158+
# # Setup extensions
159+
COPY --from=walg /tmp/wal-g /usr/local/bin/
160+
161+
# # Initialise configs
162+
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf
163+
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf
164+
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf
165+
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf
166+
COPY --chown=postgres:postgres ansible/files/postgresql_config/supautils.conf.j2 /etc/postgresql-custom/supautils.conf
167+
COPY --chown=postgres:postgres ansible/files/postgresql_extension_custom_scripts /etc/postgresql-custom/extension-custom-scripts
168+
COPY --chown=postgres:postgres ansible/files/pgsodium_getkey_urandom.sh.j2 /usr/lib/postgresql/bin/pgsodium_getkey.sh
169+
COPY --chown=postgres:postgres ansible/files/postgresql_config/custom_read_replica.conf.j2 /etc/postgresql-custom/read-replica.conf
170+
COPY --chown=postgres:postgres ansible/files/postgresql_config/custom_walg.conf.j2 /etc/postgresql-custom/wal-g.conf
171+
COPY --chown=postgres:postgres ansible/files/walg_helper_scripts/wal_fetch.sh /home/postgres/wal_fetch.sh
172+
COPY ansible/files/walg_helper_scripts/wal_change_ownership.sh /root/wal_change_ownership.sh
173+
174+
RUN sed -i \
175+
-e "s|#unix_socket_directories = '/tmp'|unix_socket_directories = '/var/run/postgresql'|g" \
176+
-e "s|#session_preload_libraries = ''|session_preload_libraries = 'supautils'|g" \
177+
-e "s|#include = '/etc/postgresql-custom/supautils.conf'|include = '/etc/postgresql-custom/supautils.conf'|g" \
178+
-e "s|#include = '/etc/postgresql-custom/wal-g.conf'|include = '/etc/postgresql-custom/wal-g.conf'|g" /etc/postgresql/postgresql.conf && \
179+
echo "cron.database_name = 'postgres'" >> /etc/postgresql/postgresql.conf && \
180+
#echo "pljava.libjvm_location = '/usr/lib/jvm/java-11-openjdk-${TARGETARCH}/lib/server/libjvm.so'" >> /etc/postgresql/postgresql.conf && \
181+
echo "pgsodium.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
182+
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
183+
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
184+
usermod -aG postgres wal-g && \
185+
mkdir -p /etc/postgresql-custom && \
186+
chown postgres:postgres /etc/postgresql-custom
187+
188+
# Remove items from postgresql.conf for PG 18 (remove unsupported extensions)
189+
RUN sed -i 's/ timescaledb,//g;' "/etc/postgresql/postgresql.conf"
190+
#as of pg 16.4 + this db_user_namespace totally deprecated and will break the server if setting is present
191+
RUN sed -i 's/db_user_namespace = off/#db_user_namespace = off/g;' "/etc/postgresql/postgresql.conf"
192+
# Remove more extensions that don't support PG 18 yet
193+
RUN sed -i 's/ timescaledb,//g; s/ plv8,//g; s/ pgjwt,//g; s/ pgaudit,//g' "/etc/postgresql-custom/supautils.conf"
194+
195+
196+
197+
# # Include schema migrations
198+
COPY migrations/db /docker-entrypoint-initdb.d/
199+
COPY ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql /docker-entrypoint-initdb.d/init-scripts/00-schema.sql
200+
COPY ansible/files/stat_extension.sql /docker-entrypoint-initdb.d/migrations/00-extension.sql
201+
202+
# # Add upstream entrypoint script pinned for now to last tested version
203+
COPY --from=gosu /usr/local/bin/gosu /usr/local/bin/gosu
204+
ADD --chmod=0755 \
205+
https://github.com/docker-library/postgres/raw/889f9447cd2dfe21cccfbe9bb7945e3b037e02d8/17/bullseye/docker-entrypoint.sh \
206+
/usr/local/bin/docker-entrypoint.sh
207+
208+
RUN mkdir -p /var/run/postgresql && chown postgres:postgres /var/run/postgresql
209+
210+
ENTRYPOINT ["docker-entrypoint.sh"]
211+
212+
HEALTHCHECK --interval=2s --timeout=2s --retries=10 CMD pg_isready -U postgres -h localhost
213+
STOPSIGNAL SIGINT
214+
EXPOSE 5432
215+
216+
ENV POSTGRES_HOST=/var/run/postgresql
217+
ENV POSTGRES_USER=supabase_admin
218+
ENV POSTGRES_DB=postgres
219+
ENV POSTGRES_INITDB_ARGS="--allow-group-access --locale-provider=icu --encoding=UTF-8 --icu-locale=en_US.UTF-8"
220+
RUN apt-get update && apt-get install -y --no-install-recommends \
221+
locales \
222+
&& rm -rf /var/lib/apt/lists/* && \
223+
localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
224+
&& localedef -i C -c -f UTF-8 -A /usr/share/locale/locale.alias C.UTF-8
225+
RUN echo "C.UTF-8 UTF-8" > /etc/locale.gen && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && locale-gen
226+
ENV LANG en_US.UTF-8
227+
ENV LANGUAGE en_US:en
228+
ENV LC_ALL en_US.UTF-8
229+
ENV LOCALE_ARCHIVE /usr/lib/locale/locale-archive
230+
RUN mkdir -p /usr/share/postgresql/extension/ && \
231+
ln -s /usr/lib/postgresql/bin/pgsodium_getkey.sh /usr/share/postgresql/extension/pgsodium_getkey && \
232+
chmod +x /usr/lib/postgresql/bin/pgsodium_getkey.sh
233+
CMD ["postgres", "-D", "/etc/postgresql"]

ansible/vars.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ async_mode: true
55
postgres_major:
66
- "15"
77
- "17"
8+
- "18"
89
- "orioledb-17"
910

1011
# Full version strings for each major version
1112
postgres_release:
12-
postgresorioledb-17: "17.5.1.026-orioledb"
13-
postgres17: "17.6.1.005"
14-
postgres15: "15.14.1.005"
13+
postgresorioledb-17: "17.5.1.026-orioledb-rc-1"
14+
postgres17: "17.6.1.005-rc-1"
15+
postgres18: "18.0.1.000-rc-1"
16+
postgres15: "15.14.1.005-rc-1"
1517

1618
# Non Postgres Extensions
1719
pgbouncer_release: "1.19.0"

nix/checks.nix

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
pkgs-lib = pkgs.callPackage ./packages/lib.nix {
1313
psql_15 = self'.packages."psql_15/bin";
1414
psql_17 = self'.packages."psql_17/bin";
15+
psql_18 = self'.packages."psql_18/bin";
1516
psql_orioledb-17 = self'.packages."psql_orioledb-17/bin";
1617
pgroonga = self'.packages."psql_15/exts/pgroonga";
1718
inherit (self.supabase) defaults;
@@ -87,6 +88,8 @@
8788
"15"
8889
else if builtins.match "17.*" name != null then
8990
"17"
91+
else if builtins.match "18.*" name != null then
92+
"18"
9093
else if builtins.match "orioledb-17.*" name != null then
9194
"orioledb-17"
9295
else
@@ -107,6 +110,8 @@
107110
builtins.match "z_orioledb-17_.*" name != null
108111
else if version == "17" then
109112
builtins.match "z_17_.*" name != null
113+
else if version == "18" then
114+
builtins.match "z_18_.*" name != null
110115
else
111116
builtins.match "z_15_.*" name != null
112117
else
@@ -122,11 +127,14 @@
122127
version = builtins.trace "pgpkg.version is: ${pgpkg.version}" pgpkg.version;
123128
isOrioledbMatch = builtins.match "^17_[0-9]+$" version != null;
124129
isSeventeenMatch = builtins.match "^17[.][0-9]+$" version != null;
130+
isEighteenMatch = builtins.match "^18[.][0-9]+$" version != null;
125131
result =
126132
if isOrioledbMatch then
127133
"orioledb-17"
128134
else if isSeventeenMatch then
129135
"17"
136+
else if isEighteenMatch then
137+
"18"
130138
else
131139
"15";
132140
in
@@ -140,6 +148,8 @@
140148
"5535"
141149
else if (majorVersion == "15") then
142150
"5536"
151+
else if (majorVersion == "18") then
152+
"5538"
143153
else
144154
"5537";
145155

@@ -181,7 +191,7 @@
181191
grep -rn "shared_preload_libraries" "$PGTAP_CLUSTER"/postgresql.conf
182192
# Remove timescaledb if running orioledb-17 check
183193
echo "I AM ${pgpkg.version}===================================================="
184-
if [[ "${pgpkg.version}" == *"17"* ]]; then
194+
if [[ "${pgpkg.version}" == *"17"* ]] || [[ "${pgpkg.version}" == *"18"* ]]; then
185195
perl -pi -e 's/ timescaledb,//g' "$PGTAP_CLUSTER/postgresql.conf"
186196
fi
187197
#NOTE in the future we may also need to add the orioledb extension to the cluster when cluster is oriole
@@ -289,6 +299,7 @@
289299
{
290300
psql_15 = makeCheckHarness self'.packages."psql_15/bin";
291301
psql_17 = makeCheckHarness self'.packages."psql_17/bin";
302+
psql_18 = makeCheckHarness self'.packages."psql_18/bin";
292303
psql_orioledb-17 = makeCheckHarness self'.packages."psql_orioledb-17/bin";
293304
inherit (self'.packages)
294305
wal-g-2

nix/config.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ in
5050
hash = "sha256-4GMKNgCuonURcVVjJZ7CERzV9DU6SwQOC+gn+UzXqLA=";
5151
};
5252
"18" = {
53-
version = "18beta3";
54-
hash = "sha256-IdhuVe6hEwDDoiEmR9w9SL2ES4MBfPbOVoRjmtj5Ung=";
53+
version = "18rc1";
54+
hash = "sha256-saTNwO1ul9EX8ETaZ4FYKdVgACyCEpCp3uhuXkmbL0w=";
5555
};
5656
};
5757
orioledb = {

nix/ext/supautils.nix renamed to nix/ext/supautils/default.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77

88
stdenv.mkDerivation rec {
99
pname = "supautils";
10-
version = "2.9.4";
10+
version = "2.10.0";
1111

1212
buildInputs = [ postgresql ];
1313

1414
src = fetchFromGitHub {
1515
owner = "supabase";
1616
repo = pname;
1717
rev = "refs/tags/v${version}";
18-
hash = "sha256-qP9fOEWXw+wY49GopTizwxSBEGS0UoseJHVBtKS/BdI=";
18+
hash = "sha256-jhTLC7aoodjHl98nnKxh6TuznrCg28/6b++6OM05WIs=";
1919
};
2020

21+
# Fix PostgreSQL 18 compatibility by making log_skipped_evtrigs static
22+
postPatch = lib.optionalString (lib.versionAtLeast postgresql.version "18") ''
23+
sed -i 's/^bool log_skipped_evtrigs = false;/static bool log_skipped_evtrigs = false;/' src/supautils.c
24+
'';
25+
2126
installPhase = ''
2227
mkdir -p $out/lib
2328
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/src/supautils.c b/src/supautils.c
2+
index 1234567..abcdefg 100644
3+
--- a/src/supautils.c
4+
+++ b/src/supautils.c
5+
@@ -64,7 +64,7 @@ typedef struct EvictCacheState
6+
} EvictCacheState;
7+
8+
/* GUC to control whether to log an event when an event trigger is skipped */
9+
-bool log_skipped_evtrigs = false;
10+
+static bool log_skipped_evtrigs = false;
11+
12+
/* GUC to save the list of constrained extensions */
13+
char *supabase_reserved_extensions = "";

nix/overlays/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
inherit (self.packages.${final.system})
1010
postgresql_15
1111
postgresql_17
12+
postgresql_18
1213
postgresql_orioledb-17
1314
supabase-groonga
1415
switch-ext-version

nix/packages/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
pkgs-lib = pkgs.callPackage ./lib.nix {
2323
psql_15 = self'.packages."psql_15/bin";
2424
psql_17 = self'.packages."psql_17/bin";
25+
psql_18 = self'.packages."psql_18/bin";
2526
psql_orioledb-17 = self'.packages."psql_orioledb-17/bin";
2627
pgroonga = self'.packages."psql_15/exts/pgroonga";
2728
inherit (self.supabase) defaults;
@@ -47,6 +48,7 @@
4748
start-client = pkgs.callPackage ./start-client.nix {
4849
psql_15 = self'.packages."psql_15/bin";
4950
psql_17 = self'.packages."psql_17/bin";
51+
psql_18 = self'.packages."psql_18/bin";
5052
psql_orioledb-17 = self'.packages."psql_orioledb-17/bin";
5153
inherit (self.supabase) defaults;
5254
};

0 commit comments

Comments
 (0)