Config not working in timescale ha docker container

When running a timescale ha docker container, postgres config is not being used.:
Provide a TL;DR of the problem

TimescaleDB version: 2.10.1
PostgreSQL version: 14
Other software: Docker: 26.1.4
OS: Ubuntu 22.04.4
Platform: Linux x86-64
Environment: [Production, Test, Development]

  1. While running timescaledb container using below command, the timescaledb-tune updates the /home/postgres/pgdata/data/postgresql.conf file and restart the database but the changes are not reflected in the pg_settings
    docker run -d --name name --net network -p 5432:5432 -e POSTGRES_PASSWORD=password -v ā€œlocal config file pathā€:/etc/postgresql/postgresql.conf -v timescaledb-volume:/home/postgres/pgdata/data timescale/timescaledb-ha:pg14-latest
  2. Even after manually changing /home/postgres/pgdata/data/postgresql.conf file and restarting the docker container the changes are not reflected in the pg_settings. What is the recommended way to restart the database so that changes are picked?
  3. The external config file is not picked while running the following command to start a docker container which works while using timescale/timescaledb:2.10.1-pg14 image:
    docker run -d --name name --net network -p 5432:5432 -e POSTGRES_PASSWORD=password -v ā€œlocal config file pathā€:/etc/postgresql/postgresql.conf timescale/timescaledb-ha:pg14-latest postgres -c ā€˜config_file=/etc/postgresql/postgresql.conf’

Notes:

  1. The image timescale/timescaledb:2.10.1-pg14 does not contain timescaledb toolkit and i.e. why we are using timescale/timescaledb-ha image. As the apk package manager in timescale/timescaledb:2.10.1-pg14 container is not able to find the timescaledb-toolkit package
  2. We are mounting a managed docker volume pointing to /home/postgres/pgdata/data

If you have related logs or config files please share them. This is a public forum please remove or disguise any identifying information such as usernames, passwords, domains, IP addresses before uploading files.

Hi Venkat, it’s confusing if this command is working or not. Can you clarify?

The command is working. But, the config file is not being considered.

I think I know what’s going on:

What I see is that you’re confused with:
-c ā€˜config_file=/etc/postgresql/postgresql.conf’

Which I think -c will just allow you to use one pair of configuration you want from the postgresql.conf.

Look my docker-compose file which needs to setup a configuration for the server:

 embed_ollama_llama3:
    image: timescale/timescaledb-ha:pg16
    container_name: embed_ollama_llama3
    ports:
      - "5434:5432"
    volumes:
      - ./embed_ollama_llama3:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=your_password
      - POSTGRES_DB=embed_ollama_llama3_db
      - POSTGRES_USER=embed_ollama_llama3_user
    command: "postgres -c ai.ollama_host=http://host.docker.internal:11434"

As you can see the command is using postgres -c and then I just make a real time config replacement but not the config_file itself.

Hi jonatasdp,

I’m trying to use your example, to set the Postgres Timescaledb configuration parameters at runtime.

I would need to set the memory and CPU values (max_connections, work_mem, max_wal_size, etc.) ​​using docker-compose based on the resources assigned to the container.

In fact, it seams that when the timescaledb container starts, timescaledb-tune is automatically started, which sets memory values ​​based on host resources rather than container resources.

I would like to set these parameters via docker-compose and not via dockerfile, so that I can configure them at runtime, based on the resources available for the different production environments.

Below, the part of my docker-compose related to the postgres container based on (timescale/timescaledb:2.1.1-pg12).

  postgres-prod:
    image: gitlab.xxxx.xxx:xxxx/postgres-prod:$Env:TAG
    volumes:
      - postgres-volume-prod:/var/lib/postgresql/data
      - postgres-backup-temporary:/var/backups/data
    deploy:
      endpoint_mode: dnsrr
      resources:
        limits:
          cpus: "0.50"
          memory: "1G"
    logging:
      driver: "json-file"
      options:
        max-size: 10m
        max-file: "10"
    command: "postgres -c shared_buffers=256MB"

But the postgres timescaledb container doesn’t start and returns the error ā€œError: positional arguments are not supported: [ā€˜postgres’, ā€˜-c’, ā€˜shared_buffers=256MB’]ā€

Another question, if possible…can I mix/set some variables in the dockerfile (ENV) and other variables in the docker-compose (environment)? Or are Dockerfile variables ignored if there is an environmnet section in docker-compose?

Thank you in advance.
Best regards

@matteo.castelli first thing: pg12 is not supported anymore. Please, use latest versions to test this out to guarantee you got the best.

My understanding is that the timescaledb-tune runs inside the container and would not have access to the configuration of the external machine. Can you share more of how you did it?

About the variables mix, yes.
You can declare ENV SOME_VAR=staging on your dockerfile and then on the docker-compose, you can use the environment too:

# docker-compose.yml
version: '3'
services:
  app:
    build: .
    environment:
      - SOME_VAR=something-else

Hi jonatasdp,

Thanks so much for replying to me.

We install Postgres Timescaledb as a container in a docker container stack.
As you can see from the yml portion, we allocate 1GB of RAM to the Postgres Container.

Normally, we install Docker on an Ubuntu Server VM with 8GB of RAM and timescale-tune seems to correctly calculate the Postgres resources related to 1GB of container RAM (shared_buffers = 256MB,
work_mem = 3276kB, maintenance_work_mem = 128MB, max_wal_size = 1GB).

In some installations, we installed the same docker stack on an Ubuntu Server VM with 32GB of RAM; in these cases, although the container is always reserved 1GB of RAM, timescaledb-tune sets higher resources that exceed the RAM assigned to the container (shared_buffers = 8023MB, work_mem = 10270kB, maintenance_work_mem = 2047MB,
max_wal_size = 1GB, min_wal_size = 512MB).
It seems that timescaledb-tune (sometimes) refers to host resources instead of container resources.

This behavior seems to be confirmed here and here.

But…
Regardless of how timescaledb-tune works, we would like to be able to specify the resources (max_connections, work_mem, max_wal_size, etc.), in the docker-compose file so that we can configure them at runtime based on the RAM/CPU available on the VM.

We tried adding the command you posted above to the docker-compose file (command: ā€œpostgres -c shared_buffers=256MBā€), but, both with the ā€œtimescale/timescaledb:2.1.1-pg12ā€ image and with the ā€œtimescale/timescaledb:2.18.2-pg17ā€ image, the container does not start and returns the error "Error: positional arguments are not supported: [ā€˜postgres’, ā€˜-c’, ā€˜shared_buffers=256MB’]ā€.

How can we pass Postgres configuration parameters into the docker-compose file?

Thank you
Best regards

Hi @jonatasdp

Do you have any tips for configuring Postgres TimascaleDB using docker-compose?

Thank you
Best regards

Hi @matteo.castelli, what exactly tips are you looking for?

as it runs the timescaledb tune, it already tweak all recommendations.

Hi @jonatasdp

Haven’t you already read my preavious post about TimescaleDB tune?

But…
Regardless of how timescaledb-tune works, we would like to be able to specify the resources (max_connections, work_mem, max_wal_size, etc.), in the docker-compose file so that we can configure them at runtime based on the RAM/CPU available on the VM.

We tried adding the command you posted above to the docker-compose file (command: ā€œpostgres -c shared_buffers=256MBā€), but, both with the ā€œtimescale/timescaledb:2.1.1-pg12ā€ image and with the ā€œtimescale/timescaledb:2.18.2-pg17ā€ image, the container does not start and returns the error "Error: positional arguments are not supported: [ā€˜postgres’, ā€˜-c’, ā€˜shared_buffers=256MB’]ā€.

How can we pass Postgres configuration parameters into the docker-compose file?

Yes, I probably missed the connection because I help too many folks in the community. I’m sorry about that.

I remember I had a similar issue. You can inherit the image and then override the postgres.conf

Example of postgresql.conf:

# Memory Configuration
shared_buffers = '1GB'
effective_cache_size = '3GB'
maintenance_work_mem = '256MB'
work_mem = '64MB'

# Checkpointing Configuration
checkpoint_completion_target = 0.9
checkpoint_timeout = '30min'
max_wal_size = '16GB'
min_wal_size = '4GB'

# WAL Configuration
wal_buffers = '16MB'
wal_compression = on
full_page_writes = off

Now in the compose file:

  postgres:
    shm_size: '3gb'
    image: timescale/timescaledb-ha:pg16
    container_name: postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: TEST!timescale
      POSTGRES_DB: TEST
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 10s
      retries: 10
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./postgresql.conf:/etc/postgresql/postgresql.conf
    command: postgres -c 'config_file=/etc/postgresql/postgresql.conf'

volumes:
  postgres_data:
    name: postgres_data
    # Add this driver option to always start fresh
    driver_opts:
      type: tmpfs
      device: tmpfs

Now checking the config:

jonatasdp@moon ~/c/t/TimescalePOC (main)> docker compose exec postgres psql -U postgres -c "SHOW shared_buffers;" -c "SHOW effective_cache_size;"
 shared_buffers
----------------
 1GB
(1 row)

 effective_cache_size
----------------------
 3GB
(1 row)

You can check my example here.

Yes, I probably missed the connection because I help too many folks in the community. I’m sorry about that.

No problem @jonatasdp…I figured you might be busy on other matters…

Ok, so it seems it is not possible to add a list of postgres -c commands directly in the docker-compose file, but it is necessary to rely on an additional ā€œpostgresql.confā€ file and copy it inside the container/volume.
It would have been nice to be able to do everything in the docker-compose file where I already have to edit the resources (CPU and RAM) of the container.

Thanks so much for the support…I’ll do some tests in the next few days.

1 Like