From e4d877059c7f8bc2a11324e52fa254e4b14070af Mon Sep 17 00:00:00 2001 From: John Hampton Date: Fri, 12 Apr 2024 08:14:38 -0700 Subject: [PATCH 1/2] fix(postgres): fix pg_isready issue with empty listen_addresses This commit resolves the issue where `pg_isready` would fail when `socketDir` is set and `listen_addresses` is empty. `pg_isready` is now modified to leverage `socketDir` when it is available. --- nix/postgres/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/postgres/default.nix b/nix/postgres/default.nix index 8611e03f..f9d114e7 100644 --- a/nix/postgres/default.nix +++ b/nix/postgres/default.nix @@ -323,7 +323,7 @@ in ''; }; pg_isreadyArgs = [ - "-h ${config.listen_addresses}" + (if config.socketDir != "" then "-h $(readlink -f \"${config.socketDir}\")" else "-h ${config.listen_addresses}") "-p ${toString config.port}" "-d template1" ] ++ (lib.optional (config.superuser != null) "-U ${config.superuser}"); From 0922b13db8eff1ab8819e3202d2045a32ec719bf Mon Sep 17 00:00:00 2001 From: John Hampton Date: Sat, 13 Apr 2024 17:56:50 -0700 Subject: [PATCH 2/2] test(postgres): set socketDir with empty listen_addresses Test a postgres service with socketDir set and empty listen_addresses. --- nix/postgres/postgres_test.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nix/postgres/postgres_test.nix b/nix/postgres/postgres_test.nix index d2b0580e..1adf9789 100644 --- a/nix/postgres/postgres_test.nix +++ b/nix/postgres/postgres_test.nix @@ -16,8 +16,19 @@ } ]; }; + services.postgres."pg3" = { + enable = true; + socketDir = "./test/new/socket/path2"; + listen_addresses = ""; + initialDatabases = [ + { + name = "test-db"; + } + ]; + }; # avoid both the processes trying to create `data` directory at the same time settings.processes."pg2-init".depends_on."pg1-init".condition = "process_completed_successfully"; + settings.processes."pg3-init".depends_on."pg2-init".condition = "process_completed_successfully"; settings.processes.test = let cfg = config.services.postgres."pg1"; @@ -37,12 +48,16 @@ # schemas test echo "SELECT * from users where user_name = 'test_user';" | psql -h 127.0.0.1 -p 5433 -d sample-db | grep -q test_user + + # listen_addresses test + echo "SELECT 1 FROM pg_database where datname = 'test-db';" | psql -h "$(readlink -f ${config.services.postgres.pg3.socketDir})" -d postgres | grep -q 1 ''; name = "postgres-test"; }; depends_on = { "pg1".condition = "process_healthy"; "pg2".condition = "process_healthy"; + "pg3".condition = "process_healthy"; }; }; }