Replace nc -z with pg_isready for PostgreSQL readiness check#305
Open
honteng wants to merge 1 commit intotemporalio:mainfrom
Open
Replace nc -z with pg_isready for PostgreSQL readiness check#305honteng wants to merge 1 commit intotemporalio:mainfrom
honteng wants to merge 1 commit intotemporalio:mainfrom
Conversation
nc -z only verifies that the TCP port is open, not that PostgreSQL is actually ready to accept queries. pg_isready is the official PostgreSQL utility that checks connection readiness (exit 0 = accepting connections, exit 1 = rejecting/still starting), providing a more reliable wait. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nc -zwithpg_isreadyin thewait_for_postgres()function (docker/auto-setup.sh).nc -zonly checks whether the TCP port is open, which can return success before PostgreSQL is actually ready to accept queries (e.g., during crash recovery or startup).pg_isreadyis the official PostgreSQL client utility that performs a proper connection readiness check—it returns exit code 0 only when the server is accepting connections.postgresql-clientpackage to theauto-setupstage inserver.Dockerfileto makepg_isreadyavailable at runtime.Motivation
In environments where PostgreSQL takes time to initialize (large databases, slow storage, replicas catching up),
nc -zcan prematurely report the database as ready. This causestemporal-sql-toolschema setup commands to fail because the port is open but PostgreSQL is still in recovery. Usingpg_isreadyeliminates this race condition.Test plan
make build-native— confirm Docker images build successfully with the newpostgresql-clientpackagemake test— runs docker-compose integration test (PostgreSQL backend by default), confirming the readiness check works end-to-endpg_isreadycorrectly waits when PostgreSQL is slow to start (e.g., by delaying PostgreSQL startup in compose)🤖 Generated with Claude Code