Data quality checks: warehouse "connection refused" in CI
A data quality tool tried to open a warehouse connection and got "connection refused". The database service is not running in CI, or the host and port point somewhere nothing is listening.
What this error means
Great Expectations, Soda, dbt, or a pytest query fails at connect time with "connection refused" or "could not connect to server", before any check runs.
data quality
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError)
connection to server at "localhost" (127.0.0.1), port 5432 failed:
Connection refusedCommon causes
No warehouse service in the job
The pipeline expects a live database but none was started as a service container, so nothing listens on the port.
The tool connected before the service was ready
The database container is still starting; the quality step runs before it accepts connections.
How to fix it
Run the warehouse as a service with a health check
- Add the database as a service container.
- Add a health check so the job waits until it accepts connections.
- Point the tool at the service host and port.
.github/workflows/ci.yml
services:
postgres:
image: postgres:16
env: { POSTGRES_PASSWORD: postgres }
ports: ['5432:5432']
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 5s
--health-timeout 5s --health-retries 10Wait for readiness before checks
Even with a service, wait on the port explicitly before running validations so a slow start does not fail the step.
Terminal
until pg_isready -h localhost -p 5432; do sleep 1; doneHow to prevent it
- Define the warehouse as a service container with health checks.
- Wait on readiness before quality steps.
- Use the service hostname, not localhost, where the network requires it.
Related guides
Data quality checks: warehouse "authentication failed" in CIFix "authentication failed" from data quality tools in CI. The warehouse credentials or OIDC token are missin…
Soda Core data source connection failed in CIFix Soda Core data source connection failures in CI. The scan cannot reach the warehouse because the host, po…
Data quality checks: "relation ... does not exist" in CIFix "table/relation does not exist" from data quality tools in CI. Quality checks ran before the models or tr…