Temporal with custom Postgres DB

Hello,

I started learning temporal recently. i understand temporal can be configured with multiple database including postgres. but i noticed postgres is part of temporal docker compose. I would like to know if it is possible to make temporal use our local postgres sql. if yes could you please share how to configure that. i tried to modify docker-compose-postgres file but i am failed to do it because not sure what are the values to be changed? could you please help on this?

Hi @tamiliniyan

Take a look at connectAdr in docker config template. It shows the env vars used to create the connection to your db.
So in your docker compose environment section for the temporal container you can set
POSTGRES_SEEDS to the db address and
DB_PORT to the port
(as well as the user and password via POSTGRES_USER and POSTGRES_PWD).

I am not sure if you have your db running on docker or not, if you need more info on setting that up see here.

If you need to set up mTLS between temporal server and your db see this article for more info.

If it helps here is docker compose I use with postgresql db running outside docker desktop (localhost). Note I run on Mac so can use host.docker.internal for POSTGRES_SEEDS. Another option could be to start docker compose with
host network mode on and then should be able to set POSTGRES_SEEDS to localhost or 127.0.0.1.

version: "3.5"
services:
  elasticsearch:
    container_name: temporal-elasticsearch
    environment:
      - cluster.routing.allocation.disk.threshold_enabled=true
      - cluster.routing.allocation.disk.watermark.low=512mb
      - cluster.routing.allocation.disk.watermark.high=256mb
      - cluster.routing.allocation.disk.watermark.flood_stage=128mb
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms256m -Xmx256m
      - xpack.security.enabled=false
    image: elasticsearch:7.16.2
    ports:
      - 9200:9200
  temporal:
    container_name: temporal
    depends_on:
      - elasticsearch
    environment:
      - DB=postgresql
      - DB_PORT=5432
      - POSTGRES_USER=tsurdilovic
      - POSTGRES_PWD=
      - POSTGRES_SEEDS=host.docker.internal
      - DYNAMIC_CONFIG_FILE_PATH=config/dynamicconfig/development_es.yaml
      - ENABLE_ES=true
      - ES_SEEDS=elasticsearch
      - ES_VERSION=v7
      - PROMETHEUS_ENDPOINT=0.0.0.0:8000
    image: temporalio/auto-setup:1.16.1
    ports:
      - 7233:7233
      - 8000:8000
    volumes:
      - ./dynamicconfig:/etc/temporal/config/dynamicconfig
  temporal-admin-tools:
    container_name: temporal-admin-tools
    depends_on:
      - temporal
    environment:
      - TEMPORAL_CLI_ADDRESS=temporal:7233
    image: temporalio/admin-tools:1.16.1
    stdin_open: true
    tty: true
  temporal-ui:
    container_name: temporal-ui
    depends_on:
      - temporal
    environment:
      - TEMPORAL_ADDRESS=temporal:7233
      - TEMPORAL_CORS_ORIGINS=http://localhost:3000
    image: temporalio/ui:latest
    ports:
      - 8080:8080
  temporal-web:
    container_name: temporal-web
    depends_on:
      - temporal
    environment:
      - TEMPORAL_GRPC_ENDPOINT=temporal:7233
      - TEMPORAL_PERMIT_WRITE_API=true
      - TEMPORAL_GRPC_MAX_MESSAGE_LENGTH=67108864
    image: temporalio/web:1.14.0
    ports:
      - 8088:8088
  prometheus:
    image: prom/prometheus
    ports:
      - 9090:9090
    volumes:
      - type: bind
        source: ./deployment/prometheus/config.yml
        target: /etc/prometheus/prometheus.yml
    depends_on:
      - temporal
  grafana:
    build: './deployment/grafana'
    environment:
      - GF_AUTH_DISABLE_LOGIN_FORM=true
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    ports:
      - 8085:3000
    volumes:
      - type: bind
        source: ./deployment/grafana/provisioning/datasources
        target: /etc/grafana/provisioning/datasources
    depends_on:
      - temporal
      - prometheus

Thanks much @tihomir . i will try out this.
Btw, i see helm chart approach is not suggested for Production environment. can you also suggest how do we set up the Production?
Also, in my local after starting up the cluster when i execute my worker class, it is working fine. if i have the temporal cluster running in remote machine, how do i configure my worker class there?

i see helm chart approach is not suggested for Production environment. can you also suggest how do we set up the Production?

I think this applies for charts in the helm-charts repo. One reason is that some people might find helm to be hard to use and/or think it has limited limited functionality. Another reason is same as with the docker-compose repo, where for production we recommend installing your own db, prometheus, grafana etc, rather than using provided defaults.
See this section as well as the “Install with your own…” sections for more info.

The suggested approach is to use the helm charts as a way to generate manifests (via helm template command) for only the temporal services and then use another method for deploying those manifests, as well as use dependencies such as db, etc external to the chart.

1 Like