juspay / services-flake

NixOS-like services for Nix flakes
https://community.flake.parts/services-flake
MIT License
369 stars 31 forks source link

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

Closed johnhampton closed 6 months ago

johnhampton commented 6 months ago

This PR resolves the issue where pg_isready would fail when socketDir is set and listen_addresses is empty. pg_isready is now modified to use socketDir when it is available.

shivaraj-bh commented 6 months ago

Shoudn't this be done at a level close to the option def?

I doubt that is possible here, because then we would expect pg_isready to automatically detect, which amongst unix_socket_directories or listen_addresses to choose from based on postgresql.conf but don’t think that is supported: https://www.postgresql.org/docs/current/app-pg-isready.html

shivaraj-bh commented 6 months ago

@johnhampton could you also add a basic test services.postgres.”pg3”, that would test for empty listen_addresses and non-empty socketDir?

You can add the test here: https://github.com/juspay/services-flake/blob/main/nix/postgres/postgres_test.nix

johnhampton commented 6 months ago

@johnhampton could you also add a basic test services.postgres.”pg3”, that would test for empty listen_addresses and non-empty socketDir?

You can add the test here: https://github.com/juspay/services-flake/blob/main/nix/postgres/postgres_test.nix

@shivaraj-bh done.

johnhampton commented 6 months ago

Shoudn't this be done at a level close to the option def? Maybe:

@srid I'm not sure, I followed the code just above my change.

https://github.com/juspay/services-flake/blob/0922b13db8eff1ab8819e3202d2045a32ec719bf/nix/postgres/default.nix#L317-L322

shivaraj-bh commented 6 months ago

I doubt that is possible here, because then we would expect pg_isready to automatically detect, which amongst unix_socket_directories or listen_addresses to choose from based on postgresql.conf but don’t think that is supported: https://www.postgresql.org/docs/current/app-pg-isready.html

And primarily that is because the settings above (postgresql.conf) only applies to the server and not the client CLI utils.

I couldn’t find any documentation on the clients picking up configs from postgresql.conf, but did for the server: https://www.postgresql.org/docs/current/config-setting.html