Pg-gvm startup loop with Greenbone Community Edition

I hit a pg-gvm startup loop with Greenbone Community Edition where PostgreSQL entered crash recovery, but the container kept exiting with:

pg_ctl: server did not start in time
database system is not yet accepting connections
Consistent recovery state has not been yet reached

The root cause was that PostgreSQL needed more time to finish the end-of-recovery checkpoint, but the Greenbone pg-gvm startup script calls pg_ctlcluster
start without passing a longer pg_ctl timeout. Setting PGCTLTIMEOUT alone was not enough in my case, because the Debian pg_ctlcluster startup check still
timed out too early.

My workaround was to mount a patched copy of /usr/local/bin/start-postgresql and pass -t 900 to pg_ctl via pg_ctlcluster.

docker-compose.yml change for pg-gvm:

services:
pg-gvm:
image:ghcr.io/greenbone/pg-gvm:stable
environment:
TZ: ‘’
restart: on-failure:10
shm_size: 512mb
stop_grace_period: 120s
volumes:
- psql_data_vol:/var/lib/postgresql
- psql_socket_vol:/var/run/postgresql
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ./start-postgresql-pg-gvm:/usr/local/bin/start-postgresql:ro
depends_on:
pg-gvm-migrator:
condition: service_completed_successfully

Create the patched script from the image:

sudo docker run --rm --entrypoint /bin/sh 
 -c 
“sed ‘0,/"${POSTGRES_VERSION}" "${POSTGRES_CLUSTER}" start/s//"${POSTGRES_VERSION}" "${POSTGRES_CLUSTER}" start – -t
"${PGCTLTIMEOUT:-900}"/’ /usr/local/bin/start-postgresql” 
| sudo tee start-postgresql-pg-gvm >/dev/null

sudo chmod 755 start-postgresql-pg-gvm

Then recreate only pg-gvm:

sudo docker compose up -d --no-deps --force-recreate pg-gvm

After that, check:

sudo docker compose ps pg-gvm
sudo docker exec greenbone-community-edition-pg-gvm-1 pg_isready -h /var/run/postgresql -U gvmd -d gvmd
sudo docker compose logs --tail=100 pg-gvm

In my case pg-gvm became healthy and the log showed:

database system is ready to accept connections

Then gvmd connected and continued DB migration/analysis.