Postgresql docker health check

From: Amna Abdul Rehman <amnaarehman18(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Postgresql docker health check
Date: 2024-03-12 14:43:13
Message-ID: CAFOeHx1wpqRLcs8jSDar-Em3F3ogSetV8sJPZnDMEehc_3XWuQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

Hope this email finds you well. Currently, I have a running PostgreSQL
container, and I've encountered an issue. When my application runs
overnight, I receive the error message 'FATAL: Sorry, too many clients
already.' To address this, I increased the number of max_connections to
3000, 5000, and also 10000, but I still receive the error. Now, I'm
considering implementing a health check. Specifically, I'd like to
automatically restart the PostgreSQL container if this error occurs. How
can I achieve this with a health check in my Docker Compose?

postgres:
restart: always
image: postgres:latest
# mem_limit: 1g
ports:
- ${POSTGRES_PORT}:${POSTGRES_PORT}
volumes:
- ./data/db/postgres:/var/lib/postgresql/data:rw
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
healthcheck:
test: ["CMD-SHELL", "sh -c 'pg_isready -U ${POSTGRES_USER} -d
${POSTGRES_DB}'"]
interval: 30s
timeout: 10s
retries: 5
extra_hosts:
- "postgres:${HOST_IP}"

Best regards,
--
Amna A Rehman
*amnaarehman18(at)gmail(dot)com <amnaarehman18(at)gmail(dot)com>*

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-03-12 14:58:29 Re: could not open file "global/pg_filenode.map": Operation not permitted
Previous Message Christophe Pettus 2024-03-12 14:29:51 Re: Is it possible to keep track of SELECTs?