Skip to content

Commit d95ee44

Browse files
hunleydsamrose
andauthored
feat: Add PostgreSQL conf.d directory (#1929)
* feat: add PG 17.7 * feat: Add PostgreSQL conf.d directory Introduce a `conf.d` directory for PostgreSQL configuration to improve modularity and organization. Changes include: - Dockerfiles: Copy and chown `conf.d` to `/etc/postgresql-custom/`. - Ansible: Add `conf.d/.gitkeep` and update `postgresql.conf.j2` to include `conf.d`. - Nix: Define path for `conf.d` and add substitution for `POSTGRESQL_CONFIG_DIR`. - `run-server.sh.in`: Copy `conf.d` to the data directory and update `postgresql.conf` to include it. - `vars.yml`: Append `-INDATA253` to postgresql release versions. * Update README.md * Update nix/config.nix * Update nix/config.nix * Update ansible/vars.yml * tests: rollback this version to 17.6 --------- Co-authored-by: Sam Rose <[email protected]>
1 parent afea09d commit d95ee44

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

Dockerfile-15

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ COPY --from=groonga /tmp/groonga-plugins/plugins /usr/lib/groonga/plugins
173173
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf
174174
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf
175175
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf
176+
COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/
176177
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf
177178
COPY --chown=postgres:postgres ansible/files/postgresql_config/supautils.conf.j2 /etc/postgresql-custom/supautils.conf
178179
COPY --chown=postgres:postgres ansible/files/postgresql_extension_custom_scripts /etc/postgresql-custom/extension-custom-scripts
@@ -193,8 +194,8 @@ RUN sed -i \
193194
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
194195
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
195196
usermod -aG postgres wal-g && \
196-
mkdir -p /etc/postgresql-custom && \
197-
chown postgres:postgres /etc/postgresql-custom
197+
mkdir -p /etc/postgresql-custom/conf.d && \
198+
chown -R postgres:postgres /etc/postgresql-custom
198199

199200
# # Include schema migrations
200201
COPY migrations/db /docker-entrypoint-initdb.d/

Dockerfile-17

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ COPY --from=groonga /tmp/groonga-plugins/plugins /usr/lib/groonga/plugins
178178
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf
179179
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf
180180
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf
181+
COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/
181182
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf
182183
COPY --chown=postgres:postgres ansible/files/postgresql_config/supautils.conf.j2 /etc/postgresql-custom/supautils.conf
183184
COPY --chown=postgres:postgres ansible/files/postgresql_extension_custom_scripts /etc/postgresql-custom/extension-custom-scripts
@@ -198,8 +199,8 @@ RUN sed -i \
198199
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
199200
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
200201
usermod -aG postgres wal-g && \
201-
mkdir -p /etc/postgresql-custom && \
202-
chown postgres:postgres /etc/postgresql-custom
202+
mkdir -p /etc/postgresql-custom/conf.d && \
203+
chown -R postgres:postgres /etc/postgresql-custom
203204

204205
# Remove items from postgresql.conf
205206
RUN sed -i 's/ timescaledb,//g;' "/etc/postgresql/postgresql.conf"

Dockerfile-orioledb-17

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ COPY --from=groonga /tmp/groonga-plugins/plugins /usr/lib/groonga/plugins
178178
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql.conf.j2 /etc/postgresql/postgresql.conf
179179
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_hba.conf.j2 /etc/postgresql/pg_hba.conf
180180
COPY --chown=postgres:postgres ansible/files/postgresql_config/pg_ident.conf.j2 /etc/postgresql/pg_ident.conf
181+
COPY --chown=postgres:postgres ansible/files/postgresql_config/conf.d /etc/postgresql-custom/
181182
COPY --chown=postgres:postgres ansible/files/postgresql_config/postgresql-stdout-log.conf /etc/postgresql/logging.conf
182183
COPY --chown=postgres:postgres ansible/files/postgresql_config/supautils.conf.j2 /etc/postgresql-custom/supautils.conf
183184
COPY --chown=postgres:postgres ansible/files/postgresql_extension_custom_scripts /etc/postgresql-custom/extension-custom-scripts
@@ -198,8 +199,8 @@ RUN sed -i \
198199
echo "vault.getkey_script= '/usr/lib/postgresql/bin/pgsodium_getkey.sh'" >> /etc/postgresql/postgresql.conf && \
199200
echo 'auto_explain.log_min_duration = 10s' >> /etc/postgresql/postgresql.conf && \
200201
usermod -aG postgres wal-g && \
201-
mkdir -p /etc/postgresql-custom && \
202-
chown postgres:postgres /etc/postgresql-custom
202+
mkdir -p /etc/postgresql-custom/conf.d && \
203+
chown -R postgres:postgres /etc/postgresql-custom
203204

204205
# Remove items from postgresql.conf
205206
RUN sed -i 's/ timescaledb,//g;' "/etc/postgresql/postgresql.conf"

ansible/files/postgresql_config/conf.d/.gitkeep

Whitespace-only changes.

ansible/files/postgresql_config/postgresql.conf.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,6 @@ jit_provider = 'llvmjit' # JIT library to use
750750
# default postgresql.conf. Note that these are directives, not variable
751751
# assignments, so they can usefully be given more than once.
752752

753-
#include_dir = '...' # include files ending in '.conf' from
754-
# a directory, e.g., 'conf.d'
755753
#include_if_exists = '...' # include file only if it exists
756754
#include = '...' # include file
757755

@@ -769,6 +767,7 @@ include = '/etc/postgresql-custom/read-replica.conf'
769767
# supautils specific configurations
770768
#include = '/etc/postgresql-custom/supautils.conf'
771769

770+
include_dir = '/etc/postgresql-custom/conf.d' # include files ending in '.conf' from a directory, e.g., 'conf.d'
772771
#------------------------------------------------------------------------------
773772
# CUSTOMIZED OPTIONS
774773
#------------------------------------------------------------------------------

ansible/tasks/setup-postgres.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
- '/home/postgres'
116116
- '/var/lib/postgresql/data'
117117
- '/var/log/postgresql'
118+
- '/etc/postgresql-custom/conf.d'
118119
loop_control:
119120
loop_var: 'pg_dir_item'
120121

@@ -137,6 +138,7 @@
137138
loop:
138139
- '/etc/postgresql'
139140
- '/etc/postgresql-custom'
141+
- '/etc/postgresql-custom/conf.d'
140142
loop_control:
141143
loop_var: 'pg_config_dir_item'
142144

nix/packages/lib.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
name = "postgresql.conf";
3737
path = ../../ansible/files/postgresql_config/postgresql.conf.j2;
3838
};
39+
configConfDir = builtins.path {
40+
name = "conf.d";
41+
path = ../../ansible/files/postgresql_config/conf.d;
42+
};
3943
supautilsConfigFile = builtins.path {
4044
name = "supautils.conf";
4145
path = ../../ansible/files/postgresql_config/supautils.conf.j2;
@@ -72,13 +76,19 @@
7276
else
7377
"${pkgs.glibcLocales}/lib/locale/locale-archive";
7478

79+
postgresqlConfigBaseDir = builtins.path {
80+
name = "postgresql_config";
81+
path = ../../ansible/files/postgresql_config;
82+
};
83+
7584
substitutions = {
7685
SHELL_PATH = "${pkgs.bash}/bin/bash";
7786
PGSQL_DEFAULT_PORT = "${defaults.port}";
7887
PGSQL_SUPERUSER = "${defaults.superuser}";
7988
PSQL15_BINDIR = "${psql_15}";
8089
PSQL17_BINDIR = "${psql_17}";
8190
PSQL_CONF_FILE = "${paths.pgconfigFile}";
91+
POSTGRESQL_CONFIG_DIR = "${postgresqlConfigBaseDir}";
8292
PSQLORIOLEDB17_BINDIR = "${psql_orioledb-17}";
8393
PGSODIUM_GETKEY = "${paths.getkeyScript}";
8494
READREPL_CONF_FILE = "${paths.readReplicaConfigFile}";

nix/tools/run-server.sh.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ fi
215215
echo "NOTE: patching postgresql.conf files"
216216
cp "$PG_HBA_FILE" "$DATDIR/pg_hba.conf"
217217
cp "$PG_IDENT_FILE" "$DATDIR/pg_ident.conf"
218+
# Copy entire conf.d directory from postgresql_config
219+
POSTGRESQL_CONFIG_DIR="@POSTGRESQL_CONFIG_DIR@"
220+
cp -r "$POSTGRESQL_CONFIG_DIR/conf.d" "$DATDIR/"
221+
222+
# Make conf.d files writable (they're read-only from Nix store)
223+
chmod -R u+w "$DATDIR/conf.d"
224+
218225
cp "$READREPL_CONFIG_FILE" "$DATDIR/read-replica.conf"
219226
mkdir -p "$DATDIR/extension-custom-scripts"
220227
cp -r "$EXTENSION_CUSTOM_SCRIPTS"/* "$DATDIR/extension-custom-scripts"
@@ -236,6 +243,7 @@ vault.getkey_script = '$PGSODIUM_GETKEY_SCRIPT'" \
236243
-e "s|include = '/etc/postgresql-custom/read-replica.conf'|include = '$DATDIR/read-replica.conf'|" \
237244
-e "\$a\\
238245
session_preload_libraries = 'supautils'" \
246+
-e "s|include_dir = '/etc/postgresql-custom/conf.d'|include_dir = '$DATDIR/conf.d'|" \
239247
"$PSQL_CONF_FILE" > "$DATDIR/postgresql.conf"
240248

241249
# Function to configure OrioleDB specific settings

0 commit comments

Comments
 (0)