Set Postgres max_connections in Docker Compose


This article goes over how to set PostgreSQL max_connections in Docker Compose.

Prerequisites

Docker Compose

In docker-compose.yml, add a command to set max_connections to 250:

services:
  database:
    image: postgres:latest
    command: postgres -c 'max_connections=250'

The command does the same thing as running the SQL query:

ALTER SYSTEM SET max_connections = 250;

Start your database container:

docker compose up database

Run the SQL query to verify max_connections is set:

SHOW max_connections;


Please support this site and join our Discord!