Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres): fix pg_isready issue with empty listen_addresses #165

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix/postgres/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
15 changes: 15 additions & 0 deletions nix/postgres/postgres_test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
};
};
}
Loading