mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-19 08:17:11 +03:00
fix(postgres): empty socketDir
by default (#160)
resolves #139 > empty `unix_socket_directories` means not listening on any Unix-domain sockets, in which case only TCP/IP sockets can be used to connect to the server. see: https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES * use TCP/IP by default for health check
This commit is contained in:
parent
3090d6f489
commit
18d5c1d168
@ -20,6 +20,9 @@
|
||||
{#socket-path}
|
||||
### Unix-domain socket path is too long
|
||||
|
||||
> [!warning]
|
||||
> Only relevant if `socketDir` is set. If not, postgres uses TCP/IP by default.
|
||||
|
||||
We already talk about this in the [data directory guide](datadir.md#socket-path). In case of postgres, you can set `socketDir` while keeping the `dataDir` unchanged.
|
||||
|
||||
>[!note]
|
||||
|
@ -52,8 +52,12 @@ in
|
||||
|
||||
socketDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.dataDir;
|
||||
default = "";
|
||||
description = "The DB socket directory";
|
||||
defaultText = ''
|
||||
An empty value specifies not listening on any Unix-domain sockets, in which case only TCP/IP sockets can be used to connect to the server.
|
||||
See: https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-UNIX-SOCKET-DIRECTORIES
|
||||
'';
|
||||
};
|
||||
|
||||
# Based on: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
|
||||
@ -128,7 +132,7 @@ in
|
||||
listen_addresses = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Listen address";
|
||||
default = "";
|
||||
default = "127.0.0.1";
|
||||
example = "127.0.0.1";
|
||||
};
|
||||
|
||||
@ -309,13 +313,17 @@ in
|
||||
text = ''
|
||||
set -euo pipefail
|
||||
PGDATA=$(readlink -f "${config.dataDir}")
|
||||
PGSOCKETDIR=$(readlink -f "${config.socketDir}")
|
||||
export PGDATA
|
||||
postgres -k "$PGSOCKETDIR"
|
||||
${ if config.socketDir != "" then ''
|
||||
PGSOCKETDIR=$(readlink -f "${config.socketDir}")
|
||||
postgres -k "$PGSOCKETDIR"
|
||||
'' else ''
|
||||
postgres
|
||||
''}
|
||||
'';
|
||||
};
|
||||
pg_isreadyArgs = [
|
||||
"-h $(readlink -f \"${config.socketDir}\")"
|
||||
"-h ${config.listen_addresses}"
|
||||
"-p ${toString config.port}"
|
||||
"-d template1"
|
||||
] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}");
|
||||
|
@ -97,17 +97,24 @@ in
|
||||
# Setup config
|
||||
echo "Setting up postgresql.conf"
|
||||
cp ${configFile} "$PGDATA/postgresql.conf"
|
||||
# Create socketDir if it doesn't exist
|
||||
if [ ! -d "${config.socketDir}" ]; then
|
||||
echo "Creating socket directory"
|
||||
mkdir -p "${config.socketDir}"
|
||||
fi
|
||||
# Create socketDir if it doesn't exist and it is not empty
|
||||
${lib.optionalString (config.socketDir != "") ''
|
||||
if [ ! -d "${config.socketDir}" ]; then
|
||||
echo "Creating socket directory"
|
||||
mkdir -p "${config.socketDir}"
|
||||
fi
|
||||
''}
|
||||
|
||||
if [[ "$POSTGRES_RUN_INITIAL_SCRIPT" = "true" ]]; then
|
||||
echo
|
||||
echo "PostgreSQL is setting up the initial database."
|
||||
echo
|
||||
PGHOST=$(mktemp -d "$(readlink -f "${config.socketDir}")/pg-init-XXXXXX")
|
||||
${ if config.socketDir != "" then ''
|
||||
PGHOST=$(mktemp -d "$(readlink -f "${config.socketDir}")/pg-init-XXXXXX")
|
||||
'' else ''
|
||||
PGHOST=$(mktemp -d /tmp/pg-init-XXXXXX)
|
||||
''
|
||||
}
|
||||
export PGHOST
|
||||
|
||||
function remove_tmp_pg_init_sock_dir() {
|
||||
|
Loading…
Reference in New Issue
Block a user