I keep getting intermittent errors with the PostgreSQL connection when running migrations. When it happens it does so at seemingly random stages during the migration however it always provides the same reason pq: the database system is shutting down in line 0: SELECT pg_advisory_unlock($1)
.
error: driver: bad connection in line 0: INSERT INTO "schema_migrations" (version, dirty) VALUES ($1, $2) and pq: the database system is shutting down in line 0: SELECT pg_advisory_unlock($1)
Exited with code 1
The .circleci/config.yml
looks as follows:
version: 2
defaults: &defaults
docker:
- image: circleci/golang:1.9.2
working_directory: /go/src/github.com/example/my-project
jobs:
checkout:
<<: *defaults
steps:
# Cache the repo for other workflow jobs.
- checkout
- save_cache:
key: repo-{{ .Environment.CIRCLE_SHA1 }}
paths:
- /go/src/github.com/example/my-project
test:
<<: *defaults
docker:
- image: circleci/golang:1.9.2
environment:
TEST_DATABASE_URL: postgres://test:@127.0.0.1:5432/circle_test?sslmode=disable
- image: circleci/postgres:9.6-alpine-postgis-ram
environment:
POSTGRES_USER: test
POSTGRES_DB: circle_test
POSTGRES_PASSWORD: ""
steps:
- run: |
go get -u -d github.com/mattes/migrate/cli github.com/lib/pq
go build -tags 'postgres' -o $GOPATH/bin/migrate github.com/mattes/migrate/cli
- restore_cache:
key: repo-{{ .Environment.CIRCLE_SHA1 }}
# Wait for PostgreSQL connection to open before running migrations.
- run: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Run database migrations
command: migrate -database ${TEST_DATABASE_URL} -path ./migrations up
- run:
name: Test
command: go test -v ./... -race
workflows:
version: 2
all:
jobs:
- checkout
- test:
requires:
- checkout
Any ideas what could cause this issue?