Search code examples
postgresqldockersed

How to increase max_connection in the official PostgreSQL Docker image


Problem

I have too many connection open using the default docker postgresql configuration

Goal

I want to extend max_connection without using a volume for mounting the configuration (I need this to be available by default for my CI environment).

I have tried to use sed to edit the configuration but this has no effect.

What is the recommended way of overriding default configuration of postgresql docker official image?


Solution

  • It is as simple as (you just override the default CMD with postgres -N 500):

    docker run -d --name db postgres:10 postgres -N 500
    

    You can check it using:

    docker run -it --rm --link db:db postgres psql -h db -U postgres
    
    show max_connections;
    
    max_connections 
    -----------------
    500
    (1 row)