Skip to main content

Self-Hosting PostHog

PostHog can be self-hosted on your own infrastructure using Docker Compose. This guide covers deployment, configuration, and scaling for production environments.
PostHog has sunset support for Kubernetes deployments. The recommended self-hosting approach is Docker Compose. See the blog post for details.

Deployment Overview

PostHog’s architecture includes:
  • Web server - Django application (main API)
  • Worker - Celery workers for background tasks
  • Plugins - Node.js service for data processing
  • ClickHouse - Columnar database for analytics
  • PostgreSQL - Relational database for metadata
  • Redis - Cache and message broker
  • Kafka - Event streaming (via Redpanda)
  • MinIO - Object storage for recordings
  • Temporal - Workflow orchestration

Quick Start with Docker Compose

Prerequisites

  • Docker Engine 20.10+
  • Docker Compose v2.0+
  • 4GB RAM minimum (8GB+ recommended)
  • 10GB disk space minimum

Installation

1

Clone Repository

2

Set Environment Variables

Create .env file:
3

Launch Services

4

Access PostHog

Navigate to https://yourdomain.com and complete setup

Docker Compose Files

PostHog provides several compose configurations:
  • docker-compose.base.yml - Base services (database, cache, etc.)
  • docker-compose.hobby.yml - Hobby deployment (all-in-one)
  • docker-compose.dev.yml - Local development
  • docker-compose.profiles.yml - Optional service profiles
From docker-compose.base.yml:1-610 and docker-compose.hobby.yml:1-440.

Environment Variables

Required Variables

Optional Configuration

Configure SMTP for notifications:
For session recordings and exports:
Enable social login:
Control feature availability:

Security Variables

Service Configuration

Web Server

The main Django application handles API requests:
GRANIAN_WORKERS controls the number of web server processes. Increase for higher concurrency.

Worker Service

Celery workers process background tasks:
Worker tasks include:
  • Event processing
  • Scheduled reports
  • Data exports
  • Async migrations

Plugins Service

Node.js service for data transformations:
Handles:
  • Data pipelines
  • GeoIP lookups
  • Custom transformations

Database Configuration

PostgreSQL

Stores user data, organizations, and metadata:
Performance tuning:

ClickHouse

Columnar database for event analytics:
Important configuration files:
  • config.xml - Server settings, networking
  • users.xml - User definitions and quotas
  • user_defined_function.xml - Custom SQL functions
ClickHouse stores all event data. Plan for 1-2GB per million events.

Scaling Your Installation

Horizontal Scaling

Scale individual services:

Resource Allocation

Recommended resources by deployment size:

Performance Optimization

1

Enable Redis Persistence

2

Configure ClickHouse Partitioning

Edit docker/clickhouse/config.xml:
3

Optimize Kafka Topics

High Availability Setup

Database Replication

PostgresSQL primary-replica setup:

Load Balancing

Use the built-in Caddy proxy or external load balancer:

Backup and Restore

PostgreSQL Backup

ClickHouse Backup

Full System Backup

Monitoring and Observability

Health Checks

All services include health checks:

Metrics Collection

PostHog exposes Prometheus metrics at /metrics:

Log Aggregation

Configure OpenTelemetry collector:

Troubleshooting

Common Issues

Check logs:
Common causes:
  • Missing environment variables
  • Port conflicts (8000, 5432, 9000 in use)
  • Insufficient disk space
  • Docker memory limits
Error: fe_sendauth: no password suppliedFix: Ensure DATABASE_URL includes credentials:
Increase memory limits:
Or reduce data retention:
Reset Kafka topics:
Check topic status:

Upgrading PostHog

1

Backup Data

Create backups of PostgreSQL and ClickHouse
2

Pull Latest Images

3

Run Migrations

4

Restart Services

5

Verify Health

Check https://yourdomain.com/_health
Always test upgrades in a staging environment first. Some migrations can take hours on large datasets.