Running Plausible Analytics Community Edition on a 4GB VPS by Tuning ClickHouse Memory
Deploy Plausible Analytics Community Edition (CE) with Docker Compose without ClickHouse OOM crashes. Mount custom ClickHouse memory-limit XML configs, disable system trace logs, and configure Traefik.
Plausible Analytics Community Edition (`ghcr.io/plausible/community-edition`) pairs an Elixir Phoenix web server with PostgreSQL (for user/site metadata) and ClickHouse (for high-speed event aggregation). Out of the box, ClickHouse assumes it owns the entire physical server—allocating up to 90% of host RAM for background merges and writing gigabytes of internal `system.trace_log`, `system.metric_log`, and `system.asynchronous_metric_log` tables to disk. By mounting a 25-line `low-memory.xml` file into `/etc/clickhouse-server/config.d/` and capping `max_server_memory_usage`, the entire Plausible CE stack runs smoothly in under 1.2 GB of RAM on a 2 GB or 4 GB VPS.
Verified Root Causes in Production Environments
- ClickHouse Default 90% Host RAM Allocation: Without an explicit `max_server_memory_usage` override, ClickHouse scales its mark cache and uncompressed cache to 90% of host memory, starving PostgreSQL and the Elixir container.
- Unbounded ClickHouse Internal System Log Tables: ClickHouse's default configuration continuously inserts millions of rows into `system.trace_log`, `system.text_log`, and `system.metric_log`, filling 20 GB+ of NVMe disk space and spiking merge RAM even on low-traffic sites.
- ClickHouse Default User Network & Password Changes in v24+: Recent ClickHouse Docker images restrict network access if `CLICKHOUSE_PASSWORD` is unset or mismatched with `CLICKHOUSE_DATABASE_URL`.
1. Create the ClickHouse Low-Memory & Log-Disabling XML Configuration
To prevent `plausible_events_db` (ClickHouse) from OOM-killing your VPS or filling your disk with internal telemetry tables, create a `clickhouse/low-memory.xml` file and mount it into `/etc/clickhouse-server/config.d/low-memory.xml:ro`.
This configuration disables internal system profiling tables (`trace_log`, `metric_log`, `asynchronous_metric_log`), caps total ClickHouse server memory at 1 GB (`1073741824` bytes), and reduces background merge thread pools.
<clickhouse>
<!-- Cap total ClickHouse server RAM to 1 GB (1073741824 bytes) -->
<max_server_memory_usage>1073741824</max_server_memory_usage>
<max_server_memory_usage_to_ram_ratio>0.4</max_server_memory_usage_to_ram_ratio>
<mark_cache_size>134217728</mark_cache_size>
<uncompressed_cache_size>134217728</uncompressed_cache_size>
<max_concurrent_queries>20</max_concurrent_queries>
<!-- Disable noisy internal system log tables that eat disk and merge RAM -->
<asynchronous_metric_log remove="remove"/>
<metric_log remove="remove"/>
<trace_log remove="remove"/>
<text_log remove="remove"/>
<part_log remove="remove"/>
<Processors_profile_log remove="remove"/>
<profiles>
<default>
<max_memory_usage>536870912</max_memory_usage>
<max_threads>2</max_threads>
</default>
</profiles>
</clickhouse>2. Production Plausible CE v2.1+ docker-compose.yml Stack
Generate your `SECRET_KEY_BASE` using `openssl rand -base64 48` before starting the stack. Note that in Plausible CE v2.1+, changing `.env` variables requires running `docker compose up -d` (not `docker compose restart`, which reuses cached container environment state).
services:
plausible_db:
image: postgres:16-alpine
restart: always
environment:
POSTGRES_DB: plausible_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- db-data:/var/lib/postgresql/data
deploy:
resources:
limits:
memory: 384M
plausible_events_db:
image: clickhouse/clickhouse-server:24.3-alpine
restart: always
environment:
CLICKHOUSE_DB: plausible_events_db
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1"
volumes:
- event-data:/var/lib/clickhouse
- ./clickhouse/low-memory.xml:/etc/clickhouse-server/config.d/low-memory.xml:ro
ulimits:
nofile:
soft: 262144
hard: 262144
deploy:
resources:
limits:
memory: 1280M
plausible:
image: ghcr.io/plausible/community-edition:v2.1.4
restart: always
command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
depends_on:
- plausible_db
- plausible_events_db
ports:
- "127.0.0.1:8000:8000"
environment:
BASE_URL: https://analytics.vexlo.cloud
SECRET_KEY_BASE: ${SECRET_KEY_BASE}
DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD}@plausible_db:5432/plausible_db
CLICKHOUSE_DATABASE_URL: http://default:${CLICKHOUSE_PASSWORD}@plausible_events_db:8123/plausible_events_db
deploy:
resources:
limits:
memory: 512M
volumes:
db-data:
event-data:3. Truncating Existing Bloated ClickHouse System Logs to Reclaim Disk Space
If you already have a running Plausible instance whose disk is 90% full due to ClickHouse system logs, apply the `low-memory.xml` file above and run `TRUNCATE TABLE IF EXISTS` against the legacy system log tables inside `plausible_events_db`.
To unlock the 'Search Terms' tab inside your self-hosted Plausible Analytics dashboard, create a Google Cloud OAuth 2.0 Client ID with the Google Search Console API enabled and add GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET to your plausible service environment variables. Additionally, mount a MaxMind GeoLite2-City.mmdb database volume if you require city-level visitor breakdowns across Indian metros (Mumbai, Bengaluru, Delhi NCR, Hyderabad, Pune, and Chennai).
# Reclaim gigabytes of disk space from existing ClickHouse internal system tables
docker compose exec plausible_events_db clickhouse-client --password "${CLICKHOUSE_PASSWORD}" -q "
TRUNCATE TABLE IF EXISTS system.trace_log;
TRUNCATE TABLE IF EXISTS system.text_log;
TRUNCATE TABLE IF EXISTS system.metric_log;
TRUNCATE TABLE IF EXISTS system.asynchronous_metric_log;
TRUNCATE TABLE IF EXISTS system.query_log;
"Pre-Deployment Verification Checklist
- Mount `low-memory.xml` into `/etc/clickhouse-server/config.d/` to cap ClickHouse RAM and remove `trace_log` / `metric_log`.
- Explicitly set `CLICKHOUSE_PASSWORD` and include it in `CLICKHOUSE_DATABASE_URL` (`http://default:PASS@plausible_events_db:8123/plausible_events_db`).
- Use `docker compose up -d` instead of `docker compose restart` whenever changing `.env` variables.
- Ensure the host CPU supports `SSE 4.2` (standard on all modern AMD EPYC / Intel Xeon VPS nodes).
Deploy on Vexlo Cloud in 60s (₹149/mo UPI)
Automated Docker & Nixpacks builds, managed PostgreSQL/Redis, and AI Deployment Doctor. Instant INR UPI for India or USD/EUR/GBP across 17 global currencies.
Frequently Asked Questions
Why is my Plausible ClickHouse container using 15 GB of disk space for a site with only 5,000 pageviews?
ClickHouse enables internal profiling tables (`system.trace_log`, `system.metric_log`, and `system.asynchronous_metric_log`) by default, which write millions of telemetry rows every day even when your website has zero visitors. Removing those tables via `config.d/low-memory.xml` and truncating them drops disk usage back under 200 MB.
Can I self-host Plausible Analytics Community Edition on a 2GB or 4GB RAM VPS?
Yes. Once ClickHouse's `max_server_memory_usage` is capped at 1 GB and its system log tables are disabled, Plausible CE, PostgreSQL, and ClickHouse combined use ~950 MB to 1.2 GB of RAM.
Why does Plausible fail to connect to ClickHouse on ClickHouse 24.x?
ClickHouse 24+ disables network access for the `default` user when no password is set. Set `CLICKHOUSE_PASSWORD` in the `plausible_events_db` service and pass that password inside `CLICKHOUSE_DATABASE_URL`.