6

I want to increase max_connections in github action Postgres service. Official document doesn't mention how to do so. Is there some clever hacks?

I tried this SO answers, which don't seem to work in github action environment.

1
  • What is the default value of max_connections in github action postgres service? Commented May 10, 2022 at 13:28

2 Answers 2

1

There is a straightforward way to do it, but you can achieve it by installing the pg client and configuration the container when the service starts. The exact steps are documented in this blog post.

The relevant code:

steps:
  - name: Install postgresql-client
    run: |
      sudo apt-get update
      sudo apt-get install --yes postgresql-client

  - name: Connect to PostgreSQL with CLI
    run: psql -c 'SELECT VERSION();'

  - name: Show PostgreSQL config file
    run: psql -c 'SHOW config_file;'

  - name: Alter max connections
    run: |
      docker exec -i postgres bash << EOF
        sed -i -e 's/max_connections = 100/max_connections = 1000/' /var/lib/postgresql/data/postgresql.conf
        sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
      EOF
      docker restart --time 0 postgres
      sleep 5

  - name: Show max connections
    run: psql -c 'SHOW max_connections;'

As there isn't an option to set a custom command for Docker services, this remains the most straightforward way of doing it.

Sign up to request clarification or add additional context in comments.

Comments

1

For postgres 16 and higher you can use POSTGRES_INITDB_ARGS:

env:
  POSTGRES_INITDB_ARGS: "-c max_connections=1500"

Note: This only is respected on the first start of the container (which is no problem on GitHub Actions).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.