Skip to content

Replace nc -z with pg_isready for PostgreSQL readiness check#305

Open
honteng wants to merge 1 commit intotemporalio:mainfrom
honteng:replace-nc-with-pg-isready
Open

Replace nc -z with pg_isready for PostgreSQL readiness check#305
honteng wants to merge 1 commit intotemporalio:mainfrom
honteng:replace-nc-with-pg-isready

Conversation

@honteng
Copy link

@honteng honteng commented Feb 13, 2026

Summary

  • Replace nc -z with pg_isready in the wait_for_postgres() function (docker/auto-setup.sh). nc -z only 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_isready is the official PostgreSQL client utility that performs a proper connection readiness check—it returns exit code 0 only when the server is accepting connections.
  • Add postgresql-client package to the auto-setup stage in server.Dockerfile to make pg_isready available at runtime.

Motivation

In environments where PostgreSQL takes time to initialize (large databases, slow storage, replicas catching up), nc -z can prematurely report the database as ready. This causes temporal-sql-tool schema setup commands to fail because the port is open but PostgreSQL is still in recovery. Using pg_isready eliminates this race condition.

Test plan

  • make build-native — confirm Docker images build successfully with the new postgresql-client package
  • make test — runs docker-compose integration test (PostgreSQL backend by default), confirming the readiness check works end-to-end
  • Verify pg_isready correctly waits when PostgreSQL is slow to start (e.g., by delaying PostgreSQL startup in compose)

🤖 Generated with Claude Code

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>
@honteng honteng requested a review from a team as a code owner February 13, 2026 18:54
@CLAassistant
Copy link

CLAassistant commented Feb 13, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants