Error to connect through socket in Bitbucket Pipelines using Postgres service
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
The user is facing issues with connecting with a Postgres service in Bitbucket Pipelines.
Diagnosis
When trying to connect to a Postgres service through a Unix socket in Bitbucket Pipelines, the user could see an error similar to the following:
1
2
3
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Cause
What happens is that connecting Postgres through the Unix socket requires some volume mounts first. However, Bitbucket Pipelines don't provide custom scripts to do volume mounts for services at this time.
Solution
The solution is to mount the Unix socket directory on the Docker container into the host, and then use it by psql to connect.
Example:
1
2
3
4
5
6
7
- step:
script:
- apt-get update && apt-get install -y postgresql-client
- docker run --name postgres -e POSTGRES_PASSWORD=password -v /opt/atlassian/pipelines/agent/build/postgresql:/var/run/postgresql -d postgres
- psql -h /opt/atlassian/pipelines/agent/build/postgresql -U postgres -c "\conninfo"
services:
- docker
Updated on March 13, 2025
Was this helpful?
Still need help?
The Atlassian Community is here for you.