Vincent Chéry
08/29/2025, 7:32 AMMarvin
08/29/2025, 7:32 AMMarvin
08/29/2025, 7:34 AMVincent Chéry
08/29/2025, 7:37 AMMarvin
08/29/2025, 7:37 AMMarvin
08/29/2025, 7:39 AMPREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECTION_URL
- Optional TLS for Postgres:
- PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CA_FILE
- PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CERT_FILE
- PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_KEY_FILE
- PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECT_ARGS_TLS_CHECK_HOSTNAME
- Workers and clients should point to the API with PREFECT_API_URL
(e.g., `http://prefect-server:4200/api`)
Example: docker-compose.yml
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: prefect
POSTGRES_PASSWORD: prefect
POSTGRES_DB: prefect
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
- ./pg-init:/docker-entrypoint-initdb.d # will run init SQL below
healthcheck:
test: ["CMD-SHELL", "pg_isready -U prefect -d prefect"]
interval: 10s
timeout: 5s
retries: 5
prefect-server:
image: prefecthq/prefect:3-latest
depends_on:
postgres:
condition: service_healthy
environment:
# Point server at Postgres
PREFECT_SERVER_DATABASE_SQLALCHEMY_CONNECTION_URL: <postgresql+psycopg://prefect:prefect@postgres:5432/prefect>
# Expose the API for workers/clients
PREFECT_API_URL: <http://prefect-server:4200/api>
# If you front this with a reverse proxy or access via a different hostname,
# set UI to point to the correct API URL for browsers:
# PREFECT_UI_API_URL: <https://your.domain.example/api>
command: >
bash -lc "prefect server start --host 0.0.0.0 --port 4200"
ports:
- "4200:4200"
# Example worker (repeat/scale as needed)
worker-1:
image: prefecthq/prefect:3-latest
depends_on:
- prefect-server
environment:
PREFECT_API_URL: <http://prefect-server:4200/api>
command: >
bash -lc "prefect worker start --pool default"
volumes:
pgdata:
Postgres init to enable pg_trgm (pg-init/001_enable_pg_trgm.sql)
CREATE EXTENSION IF NOT EXISTS pg_trgm;
Notes and tips
- You can start with one Prefect Server replica; add another and a load balancer if you want HA later. Redis still not required.
- Most scale pressure shows up in Postgres first (connections, I/O, query latency). Prefer a managed PG if you can, otherwise tune autovacuum and monitor IOPS closely.
- Workers should be placed close (network-wise) to the server and database.
Docs
- Server concepts: https://docs-3.prefect.io/v3/concepts/server
- Self-hosted guide: https://docs-3.prefect.io/v3/advanced/self-hosted
- Settings reference (env vars): https://docs-3.prefect.io/v3/api-ref/settings-ref
If you share how your workers will connect (same Docker network, across hosts, behind a reverse proxy), I can adapt the `PREFECT_API_URL`/`PREFECT_UI_API_URL` and networking details.