Skip to content

Commit 1befafe

Browse files
nix(postgrest-with-pg-...): use postgresql.conf instead of CLI arguments
This is easier to reason about and easier to extend. Also removes a tiny bit of repetition.
1 parent 70327cf commit 1befafe

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

nix/tools/withTools.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ let
1414
{ name, postgresql }:
1515
let
1616
commandName = "postgrest-with-${name}";
17+
postgresqlConf = writeText "postgresql.conf" "
18+
listen_addresses = ''
19+
log_statement = all
20+
";
1721
in
1822
checkedShellScript
1923
{
@@ -72,6 +76,10 @@ let
7276
TZ=$PGTZ initdb --no-locale --encoding=UTF8 --nosync -U postgres --auth=trust \
7377
>> "$setuplog"
7478
79+
# Append our own config to the one initdb created to avoid replacing
80+
# default values created by the latter.
81+
cat ${postgresqlConf} >> "$tmpdir/db/postgresql.conf"
82+
7583
log "Starting the database cluster..."
7684
7785
# Instead of listening on a local port, we will listen on a unix domain socket.
@@ -80,7 +88,7 @@ let
8088
# On MacOS, it's 104 chars
8189
# See: https://serverfault.com/questions/641347/check-if-a-path-exceeds-maximum-for-unix-domain-socket
8290
83-
pg_ctl -l "$tmpdir/db.log" -w start -o "-F -c listen_addresses=\"\" -c hba_file=$HBA_FILE -k $PGHOST -c log_statement=\"all\" " \
91+
pg_ctl -l "$tmpdir/db.log" -w start -o "-F -c hba_file=$HBA_FILE -k $PGHOST " \
8492
>> "$setuplog"
8593
8694
log "Creating a minimally privileged $PGUSER connection role..."
@@ -106,7 +114,7 @@ let
106114
log "Starting replica on $replica_host"
107115
108116
# We set a low max_standby_streaming_delay to make the replication conflict fail faster in tests (otherwise it waits for the default 30s)
109-
pg_ctl -D "$replica_dir" -l "$replica_dblog" -w start -o "-F -c listen_addresses=\"\" -c hba_file=$HBA_FILE -k $replica_host -c log_statement=\"all\" -c max_standby_streaming_delay=\"3s\" " \
117+
pg_ctl -D "$replica_dir" -l "$replica_dblog" -w start -o "-F -c hba_file=$HBA_FILE -k $replica_host -c max_standby_streaming_delay=\"3s\" " \
110118
>> "$setuplog"
111119
112120
>&2 echo "${commandName}: Replica enabled. You can connect to it with: psql 'postgres:///$PGDATABASE?host=$replica_host' -U postgres"

0 commit comments

Comments
 (0)