Skip to content

Commit 68366e5

Browse files
committed
feat: multigres docker pgctld
1 parent 178ca82 commit 68366e5

2 files changed

Lines changed: 332 additions & 0 deletions

File tree

Dockerfile-multigres

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ RUN for f in /nix/var/nix/profiles/default/bin/*; do \
209209
RUN chown -R postgres:postgres /usr/lib/postgresql && \
210210
chown -R postgres:postgres /usr/share/postgresql
211211

212+
RUN ln -sf /nix/var/nix/profiles/default/bin/pgctld /usr/local/bin/pgctld
213+
212214
# Strip extensions absent from pg17 vanilla build
213215
RUN sed -i 's/ timescaledb,//g; s/ plv8,//g' /etc/postgresql-custom/supautils.conf
214216

@@ -218,6 +220,7 @@ ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive
218220
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
219221
CMD pg_isready -U postgres -h localhost || true
220222
STOPSIGNAL SIGINT
223+
USER postgres
221224
EXPOSE 5432
222225

223226
ENTRYPOINT ["tail"]
@@ -260,12 +263,27 @@ RUN sed -i "s/\(shared_preload_libraries.*\)'/\1, orioledb'/" /etc/postgresql/po
260263
RUN echo "CREATE EXTENSION orioledb;" > /docker-entrypoint-initdb.d/init-scripts/00-pre-init.sql && \
261264
chown postgres:postgres /docker-entrypoint-initdb.d/init-scripts/00-pre-init.sql
262265

266+
# pgctld calls initdb without locale flags, so it picks up LANG from the environment.
267+
# OrioleDB requires C, POSIX, or ICU collations; override the base stage's en_US.UTF-8.
268+
ENV LANG=C
269+
ENV LC_ALL=C
270+
ENV LANGUAGE=C
271+
272+
COPY docker/pgctld/orioledb-postgresql.conf.tmpl /etc/pgctld/orioledb-postgresql.conf.tmpl
273+
274+
# Wrapper: injects --postgres-config-template on every pgctld call so the team's
275+
# unmodified k8s manifests and local provisioner commands work without extra flags.
276+
RUN printf '#!/bin/sh\nexec /nix/var/nix/profiles/default/bin/pgctld --postgres-config-template /etc/pgctld/orioledb-postgresql.conf.tmpl "$@"\n' \
277+
> /usr/local/bin/pgctld && \
278+
chmod +x /usr/local/bin/pgctld
279+
263280
ENV PATH="/nix/var/nix/profiles/default/bin:/usr/lib/postgresql/bin:${PATH}"
264281
ENV LOCALE_ARCHIVE=/nix/var/nix/profiles/default/lib/locale/locale-archive
265282

266283
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
267284
CMD pg_isready -U postgres -h localhost || true
268285
STOPSIGNAL SIGINT
286+
USER postgres
269287
EXPOSE 5432
270288

271289
ENTRYPOINT ["tail"]
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
# ╔══════════════════════════════════════════════════════════════════════════════╗
2+
# ║ ║
3+
# ║ PostgreSQL Configuration ║
4+
# ║ ║
5+
# ║ Generated by Multigres - Helping you Scale PostgreSQL ║
6+
# ║ ║
7+
# ║ This configuration contains optimized settings for PostgreSQL ║
8+
# ║ instances managed by Multigres.
9+
# ║ will be replaced with actual values during deployment.
10+
# ║ ║
11+
# ║ ║
12+
# ╚══════════════════════════════════════════════════════════════════════════════╝
13+
14+
15+
#------------------------------------------------------------------------------
16+
# CONNECTIONS AND AUTHENTICATION
17+
#------------------------------------------------------------------------------
18+
19+
# - Connection Settings -
20+
# Port, listen_addresses, and unix_socket_directories are passed as command-line parameters
21+
# This ensures backups remain portable across different environments
22+
max_connections = {{.MaxConnections}}
23+
24+
# - Authentication -
25+
26+
authentication_timeout = 1min # 1s-600s
27+
password_encryption = scram-sha-256 # scram-sha-256 or md5
28+
29+
# GSSAPI using Kerberos
30+
31+
# - SSL -
32+
33+
ssl = off
34+
ssl_ca_file = ''
35+
ssl_cert_file = ''
36+
ssl_crl_file = ''
37+
ssl_crl_dir = ''
38+
ssl_key_file = ''
39+
ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' # allowed SSL ciphers
40+
ssl_prefer_server_ciphers = on
41+
ssl_ecdh_curve = 'prime256v1'
42+
ssl_min_protocol_version = 'TLSv1.2'
43+
ssl_max_protocol_version = ''
44+
ssl_dh_params_file = ''
45+
ssl_passphrase_command = ''
46+
ssl_passphrase_command_supports_reload = off
47+
48+
49+
#------------------------------------------------------------------------------
50+
# RESOURCE USAGE (except WAL)
51+
#------------------------------------------------------------------------------
52+
53+
# - Memory -
54+
55+
shared_buffers = {{.SharedBuffers}} # min 128kB
56+
# (change requires restart)
57+
maintenance_work_mem = {{.MaintenanceWorkMem}} # min 1MB
58+
work_mem = {{.WorkMem}} # min 64kB
59+
60+
# - Disk -
61+
62+
# - Kernel Resources -
63+
64+
max_worker_processes = {{.MaxWorkerProcesses}} # (change requires restart)
65+
66+
# - Cost-Based Vacuum Delay -
67+
68+
# - Background Writer -
69+
70+
# - Asynchronous Behavior -
71+
72+
effective_io_concurrency = {{.EffectiveIoConcurrency}} # 1-1000; 0 disables prefetching
73+
max_parallel_workers = {{.MaxParallelWorkers}} # max number of parallel workers
74+
max_parallel_workers_per_gather = {{.MaxParallelWorkersPerGather}} # taken from max_parallel_workers
75+
max_parallel_maintenance_workers = {{.MaxParallelMaintenanceWorkers}} # taken from max_parallel_workers
76+
77+
78+
#------------------------------------------------------------------------------
79+
# WRITE-AHEAD LOG
80+
#------------------------------------------------------------------------------
81+
82+
# - Settings -
83+
84+
wal_level = logical # minimal, replica, or logical
85+
# (change requires restart)
86+
wal_buffers = {{.WalBuffers}} # min 32kB, -1 sets based on shared_buffers
87+
# (change requires restart)
88+
min_wal_size = {{.MinWalSize}}
89+
max_wal_size = {{.MaxWalSize}}
90+
wal_keep_size = 1000
91+
92+
# - Checkpoints -
93+
94+
checkpoint_completion_target = {{.CheckpointCompletionTarget}} # checkpoint target duration, 0.0 - 1.0
95+
checkpoint_flush_after = 256kB # measured in pages, 0 disables
96+
97+
# - Archiving -
98+
99+
# - Archive Recovery -
100+
101+
# These are only used in recovery mode.
102+
103+
# - Recovery Target -
104+
105+
# Set these only when performing a targeted recovery.
106+
107+
108+
#------------------------------------------------------------------------------
109+
# REPLICATION
110+
#------------------------------------------------------------------------------
111+
112+
# - Sending Servers -
113+
114+
max_wal_senders = {{.MaxWalSenders}} # max number of walsender processes
115+
# (change requires restart)
116+
max_replication_slots = {{.MaxReplicationSlots}} # max number of replication slots
117+
# (change requires restart)
118+
max_slot_wal_keep_size = 4096 # in megabytes; -1 disables
119+
120+
# - Primary Server -
121+
122+
# These settings are ignored on a standby server.
123+
124+
# - Standby Servers -
125+
126+
# These settings are ignored on a primary server.
127+
128+
# - Subscribers -
129+
130+
# These settings are ignored on a publisher.
131+
132+
133+
#------------------------------------------------------------------------------
134+
# QUERY TUNING
135+
#------------------------------------------------------------------------------
136+
137+
# - Planner Method Configuration -
138+
139+
# - Planner Cost Constants -
140+
141+
effective_cache_size = {{.EffectiveCacheSize}}
142+
random_page_cost = {{.RandomPageCost}} # same scale as above
143+
144+
# - Genetic Query Optimizer -
145+
146+
# - Other Planner Options -
147+
148+
default_statistics_target = {{.DefaultStatisticsTarget}} # range 1-10000
149+
150+
151+
#------------------------------------------------------------------------------
152+
# REPORTING AND LOGGING
153+
#------------------------------------------------------------------------------
154+
155+
# These are relevant when logging to syslog:
156+
157+
# This is only relevant when logging to eventlog (Windows):
158+
# (change requires restart)
159+
160+
# - When to Log -
161+
162+
# - What to Log -
163+
164+
log_line_prefix = '%h %m [%p] %q%u@%d ' # special values:
165+
# %a = application name
166+
# %u = user name
167+
# %d = database name
168+
# %r = remote host and port
169+
# %h = remote host
170+
# %b = backend type
171+
# %p = process ID
172+
# %P = process ID of parallel group leader
173+
# %t = timestamp without milliseconds
174+
# %m = timestamp with milliseconds
175+
# %n = timestamp with milliseconds (as a Unix epoch)
176+
# %Q = query ID (0 if none or not computed)
177+
# %i = command tag
178+
# %e = SQL state
179+
# %c = session ID
180+
# %l = session line number
181+
# %s = session start timestamp
182+
# %v = virtual transaction ID
183+
# %x = transaction ID (0 if none)
184+
# %q = stop here in non-session
185+
# processes
186+
# %% = '%'
187+
# e.g. '<%u%%%d> '
188+
log_statement = 'ddl' # none, ddl, mod, all
189+
log_timezone = 'UTC'
190+
191+
#------------------------------------------------------------------------------
192+
# PROCESS TITLE
193+
#------------------------------------------------------------------------------
194+
195+
cluster_name = 'main' # added to process titles if nonempty
196+
# (change requires restart)
197+
198+
199+
#------------------------------------------------------------------------------
200+
# STATISTICS
201+
#------------------------------------------------------------------------------
202+
203+
# - Query and Index Statistics Collector -
204+
205+
206+
# - Monitoring -
207+
208+
209+
#------------------------------------------------------------------------------
210+
# AUTOVACUUM
211+
#------------------------------------------------------------------------------
212+
213+
214+
#------------------------------------------------------------------------------
215+
# CLIENT CONNECTION DEFAULTS
216+
#------------------------------------------------------------------------------
217+
218+
# - Statement Behavior -
219+
220+
row_security = on
221+
222+
timezone = 'UTC'
223+
224+
# These settings are initialized by initdb, but they can be changed.
225+
lc_messages = 'en_US.UTF-8' # locale for system error message
226+
# strings
227+
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
228+
lc_numeric = 'en_US.UTF-8' # locale for number formatting
229+
lc_time = 'en_US.UTF-8' # locale for time formatting
230+
231+
# default configuration for text search
232+
default_text_search_config = 'pg_catalog.english'
233+
234+
# These settings are initialized by initdb, but they can be changed.
235+
lc_messages = 'en_US.UTF-8' # locale for system error message
236+
# strings
237+
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
238+
lc_numeric = 'en_US.UTF-8' # locale for number formatting
239+
lc_time = 'en_US.UTF-8' # locale for time formatting
240+
241+
# default configuration for text search
242+
default_text_search_config = 'pg_catalog.english'
243+
244+
# - Shared Library Preloading -
245+
246+
## TODO: @rafael - We are starting from a Vanilla postgres. We still
247+
## ened to do work here to make sure we start postgres with libraries that
248+
## will be used by supabase infra.
249+
# shared_preload_libraries = 'pg_stat_statements, pgaudit, plpgsql, plpgsql_check, pg_cron, pg_net, pgsodium, timescaledb, auto_explain, pg_tle, plan_filter, supabase_vault' # (change requires restart)
250+
jit_provider = 'llvmjit' # JIT library to use
251+
252+
# - Other Defaults -
253+
254+
#------------------------------------------------------------------------------
255+
# LOCK MANAGEMENT
256+
#------------------------------------------------------------------------------
257+
258+
#deadlock_timeout = 1s
259+
260+
261+
#------------------------------------------------------------------------------
262+
# VERSION AND PLATFORM COMPATIBILITY
263+
#------------------------------------------------------------------------------
264+
265+
# - Previous PostgreSQL Versions -
266+
267+
# - Other Platforms and Clients -
268+
269+
270+
#------------------------------------------------------------------------------
271+
# ERROR HANDLING
272+
#------------------------------------------------------------------------------
273+
274+
#exit_on_error = off # terminate session on any error?
275+
#restart_after_crash = on # reinitialize after backend crash?
276+
#data_sync_retry = off # retry or panic on failure to fsync
277+
# data?
278+
# (change requires restart)
279+
#recovery_init_sync_method = fsync # fsync, syncfs (Linux 5.8+)
280+
281+
282+
#------------------------------------------------------------------------------
283+
# CONFIG FILE INCLUDES
284+
#------------------------------------------------------------------------------
285+
286+
# These options allow settings to be loaded from files other than the
287+
# default postgresql.conf. Note that these are directives, not variable
288+
# assignments, so they can usefully be given more than once.
289+
290+
# Automatically generated optimizations
291+
# User-supplied custom parameters, override any automatically generated ones
292+
293+
# WAL-G specific configurations
294+
295+
#------------------------------------------------------------------------------
296+
# CUSTOMIZED OPTIONS
297+
#------------------------------------------------------------------------------
298+
299+
# Add settings for extensions here
300+
auto_explain.log_min_duration = 10s
301+
cron.database_name = 'postgres'
302+
wal_log_hints = 'on'
303+
304+
#------------------------------------------------------------------------------
305+
# ORIOLEDB
306+
# These settings activate OrioleDB as the default table storage engine.
307+
# Injected automatically by the /usr/local/bin/pgctld wrapper in variant-orioledb-17.
308+
#------------------------------------------------------------------------------
309+
shared_preload_libraries = 'orioledb'
310+
default_table_access_method = 'orioledb'
311+
orioledb.enable_rewind = true
312+
orioledb.rewind_max_time = 1200
313+
orioledb.rewind_max_transactions = 100000
314+
orioledb.rewind_buffers = 1280

0 commit comments

Comments
 (0)