Day 9: Operations and Upgrade
Goal: You know how much CPU, memory and disk Plausible needs, recognize a ClickHouse outage, send e-mails through a test mail server and rehearse an upgrade including the way back on a trial stack. · Duration: approx. 60 min · Prerequisite: Day 8
Briefing
- Plausible is frugal in operation. When idle, the application itself uses most of the memory; ClickHouse grows with the events – and with its own system tables, if you let it.
/api/healthchecks all parts at once: sessions, PostgreSQL, ClickHouse and the site cache. A monitoring system polls exactly this path.- Events first land in an in-memory buffer and are sent to ClickHouse in batches every few seconds. Whatever is in the buffer when ClickHouse is missing is lost.
- E-mails (invitations, forgotten password, reports) need SMTP. Without SMTP they fail silently in the background.
- The versions of the Community Edition are branches
in the repo (
v3.1.0,v3.2.1). An upgrade means: switch the branch,docker compose up -d. The migrations run at startup. They never run backwards.
Upgrade v3.1.0 ──► v3.2.1 Way back v3.2.1 ──► v3.1.0
git switch + up -d git switch + up -d
migrations 218 ──► 222 migrations stay at 222
data stays old code on new schema
only safe: backup from before
Drill 1: What the stack consumes
# on argo
docker stats --no-stream --format '{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}' \
| grep '^ce-' | sort
sudo sh -c 'du -sh /var/lib/docker/volumes/ce_*/_data' | sort -k2Expected (values will differ):
ce-plausible-1 4.57% 390.6MiB / 7.755GiB
ce-plausible_db-1 0.45% 99.73MiB / 7.755GiB
ce-plausible_events_db-1 9.85% 170.6MiB / 7.755GiB
67M /var/lib/docker/volumes/ce_db-data/_data
5.8M /var/lib/docker/volumes/ce_event-data/_data
84K /var/lib/docker/volumes/ce_event-logs/_data
3.3M /var/lib/docker/volumes/ce_plausible-data/_data
When idle, the application itself takes most of the memory;
ClickHouse gets by with just under 200 MiB. Part of the reason is
low-resources.xml from the Community Edition, which keeps
ClickHouse small – still, at least 2 GB of RAM is recommended for the
whole stack.
Save your progress? Sign up for free
Drill 2: Where ClickHouse needs space
# on argo
cd ~/plausible/ce
docker compose exec -T plausible_events_db clickhouse-client --query "
select database, table, formatReadableSize(sum(bytes_on_disk)) as platz
from system.parts where active group by database, table
order by sum(bytes_on_disk) desc limit 6 format TSVRaw"
grep -c 'remove="remove"' clickhouse/logs.xml
grep -o 'TTL event_date + interval [0-9]* day' clickhouse/logs.xmlExpected (values will differ):
plausible_events_db location_data 2.91 MiB
system query_log 555.57 KiB
system processors_profile_log 488.78 KiB
system asynchronous_insert_log 9.70 KiB
plausible_events_db sessions_v2 8.04 KiB
plausible_events_db acquisition_channel_source_category 7.33 KiB
7
TTL event_date + interval 30 day
ClickHouse logs about itself in tables of the system
database. The Community Edition switches seven of these logs off
completely and keeps only the query_log, which is deleted
automatically after 30 days. If you overwrite or forget the file
logs.xml during an upgrade, you will watch the disk grow
without a single new visitor.
Save your progress? Sign up for free
Drill 3: Health and logs
# on argo
curl -s -w ' %{http_code}\n' https://plausible.lab/api/health
cd ~/plausible/ce
docker compose logs plausible --since 10m --no-log-prefix 2>&1 \
| grep -o '\[[a-z]*\]' | sort | uniq -cExpected (numbers will differ):
{"sessions":"ok","postgres":"ok","clickhouse":"ok","sites_cache":"ok"} 200
81 [notice]
In quiet operation only [notice]: Plausible reloads its
caches regularly and says so every time. What matters for operations is
[warning] and [error] – that is what a log
system filters for, not everything. With --since 1h you may
see hundreds of [error] lines from
Ch.Connection: they appear when ClickHouse restarts (Day 8,
Drill 3) and stop afterwards.
Save your progress? Sign up for free
Drill 4: ClickHouse goes down
Break it: ClickHouse is stopped, for example because the disk is full or an update hangs. Beforehand, you note how many events are stored.
# on argo
cd ~/plausible/ce
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select count() from events_v2" | tee ~/plausible/tag09-vorher.txt
docker compose stop plausible_events_db 2>&1 | tail -1Symptom: Plausible reports the error but keeps accepting events.
# on argo
sleep 5
curl -s -w ' %{http_code}\n' https://plausible.lab/api/health
UA="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"
UA="$UA Chrome/140.0.0.0 Safari/537.36"
for i in 1 2 3; do
curl -s -o /dev/null -w '%{http_code} ' -H "User-Agent: $UA" \
-H "X-Forwarded-For: 203.0.113.9$i" -H 'Content-Type: application/json' \
https://plausible.lab/api/event \
-d '{"name":"pageview","url":"https://itdrills.com/books/","domain":"itdrills.com"}'
done; echoExpected:
{"sessions":"ok","postgres":"ok","clickhouse":"error","sites_cache":"ok"} 500
202 202 202
Investigate:
# on argo
sleep 20
cd ~/plausible/ce
docker compose logs plausible --since 2m --no-log-prefix 2>&1 \
| grep -E 'WriteBuffer terminating|health check failure' | cut -c1-72 | sort -uExpected:
07:27:18.835 request_id=GOn-waE-6Y9mXgAAADbB [error] Clickhouse health c
07:27:32.836 [error] GenServer Plausible.Event.WriteBuffer terminating
07:27:32.836 [error] GenServer Plausible.Session.WriteBuffer terminating
Cause: 202 means “accepted”, not
“stored”. Plausible collects events in memory (WriteBuffer)
and writes them to ClickHouse in batches. If ClickHouse cannot be
reached, the buffer terminates and its content is gone.
Fix and verify: Start ClickHouse again and count.
# on argo
cd ~/plausible/ce
docker compose start plausible_events_db 2>&1 | tail -1
until curl -sf -o /dev/null https://plausible.lab/api/health; do sleep 2; done
sleep 10
cat ~/plausible/tag09-vorher.txt
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select count() from events_v2"Expected:
Container ce-plausible_events_db-1 Started
55
55
The same number as before: the three requests never arrived anywhere.
No fix after the fact helps against this outage – only monitoring on
/api/health that raises an alert immediately.
Save your progress? Sign up for free
Drill 5: E-mail through a test mail server
Mailpit catches all mails and displays them instead of delivering them – ideal for the lab. It joins the stack as a fourth service.
# on argo
cd ~/plausible/ce
cat > compose.override.yml <<'EOF'
services:
plausible:
ports:
- 127.0.0.1:8000:8000
plausible_events_db:
volumes:
- ./clickhouse-backups.xml:/etc/clickhouse-server/config.d/backups.xml:ro
- ~/plausible/tag08/clickhouse:/backups
mailpit:
image: axllent/mailpit:v1.33.0
ports:
- 127.0.0.1:8025:8025
EOF
cat >> .env <<'EOF'
[email protected]
MAILER_NAME=Plausible Labor
SMTP_HOST_ADDR=mailpit
SMTP_HOST_PORT=1025
SMTP_HOST_SSL_ENABLED=false
EOF
docker compose up -d --quiet-pull 2>&1 | tail -1
until curl -sf -o /dev/null http://127.0.0.1:8000/api/health; do sleep 2; done
docker compose exec -T plausible env | grep '^SMTP_HOST' | sortExpected:
SMTP_HOST_ADDR=mailpit
SMTP_HOST_PORT=1025
SMTP_HOST_SSL_ENABLED=false
up -d, not restart: Compose only rereads
.env when it recreates the container (Day 1). Now trigger a
mail – “forgot password” for the lab user. The form requires a CSRF
token from the page and the matching cookie.
# on argo
J=$(mktemp)
T=$(curl -s -c "$J" https://plausible.lab/password/request-reset \
| sed -n 's/.*name="_csrf_token"[^>]*value="\([^"]*\)".*/\1/p' | head -1)
curl -s -b "$J" -o /dev/null -w 'POST %{http_code}\n' \
https://plausible.lab/password/request-reset \
--data-urlencode "_csrf_token=$T" --data-urlencode '[email protected]'
sleep 3
curl -s http://127.0.0.1:8025/api/v1/messages \
| jq -r '.messages[] | "\(.From.Address) -> \(.To[0].Address): \(.Subject)"'
rm -f "$J"Expected:
POST 200
[email protected] -> [email protected]: Plausible password reset
For a real server, the same variables hold your mail provider’s SMTP
server, port 587 or 465, SMTP_USER_NAME and
SMTP_USER_PWD. Mailpit in the browser: an SSH tunnel to
port 8025, then http://localhost:8025.
Save your progress? Sign up for free
Drill 6: Upgrade rehearsal
You do not rehearse an upgrade on the real stack. A trial stack with the previous version v3.1.0 gets a user, a site and a few events – then it is lifted to v3.2.1. As an exception, port 8002 is reachable from outside here so that you can register in the browser.
# on argo
git clone -q -b v3.1.0 --single-branch \
https://github.com/plausible/community-edition ~/plausible/probe 2>&1 \
| grep -v detached
cd ~/plausible/probe
printf 'BASE_URL=http://plausible.lab:8002\nSECRET_KEY_BASE=%s\nTOTP_VAULT_KEY=%s\n' \
"$(openssl rand -base64 48)" "$(openssl rand -base64 32)" > .env
echo 'HTTP_PORT=8000' >> .env
chmod 600 .env
printf 'services:\n plausible:\n ports:\n - 8002:8000\n' > compose.override.yml
docker compose up -d --quiet-pull 2>&1 | tail -1
until curl -sf -o /dev/null http://127.0.0.1:8002/api/health; do sleep 3; done
docker compose ps --format '{{.Service}} {{.Image}}' | grep '^plausible 'Expected:
plausible ghcr.io/plausible/community-edition:v3.1.0
In the browser: http://plausible.lab:8002/register, user
[email protected] with password
lab-plausible-123, then create the site
itdrills.com (as on Day 1). After that, five events, a
PostgreSQL backup and the state before the upgrade:
# on argo
cd ~/plausible/probe
UA="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"
UA="$UA Chrome/140.0.0.0 Safari/537.36"
for i in 1 2 3 4 5; do
curl -s -o /dev/null -H "User-Agent: $UA" -H "X-Forwarded-For: 203.0.113.6$i" \
-H 'Content-Type: application/json' http://127.0.0.1:8002/api/event \
-d '{"name":"pageview","url":"https://itdrills.com/books/","domain":"itdrills.com"}'
done
docker compose exec -T plausible_db pg_dump -U postgres -Fc plausible_db \
> ~/plausible/probe-vor-upgrade.dump
sleep 5
docker compose exec -T plausible_db psql -U postgres -d plausible_db \
-tAc "select count(*) from schema_migrations"
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select (select count() from schema_migrations), count() from events_v2"Expected:
218
51 5
218 migrations in PostgreSQL, 51 in ClickHouse, 5 events. Now the
upgrade: the clone only knows its own branch, so git fetch
has to fetch the new one first.
# on argo
cd ~/plausible/probe
git fetch -q origin v3.2.1 && git switch -q -c v3.2.1 FETCH_HEAD
git log --oneline -1
docker compose up -d --quiet-pull 2>&1 | tail -1
until curl -sf -o /dev/null http://127.0.0.1:8002/api/health; do sleep 3; done
docker compose exec -T plausible_db psql -U postgres -d plausible_db \
-tAc "select count(*) from schema_migrations"
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select (select count() from schema_migrations), count() from events_v2"Expected:
ec6c4da Update v3.2.1
222
51 5
Four new migrations in PostgreSQL, none in ClickHouse, all events
still there. .env and compose.override.yml are
not in the repo and survive the branch switch.
Save your progress? Sign up for free
Drill 7: The limit of the way back
Break it: After the upgrade, a bug shows up. The colleague simply switches back to the old version.
# on argo
cd ~/plausible/probe
git switch -q v3.1.0
docker compose up -d 2>&1 | tail -1
until curl -sf -o /dev/null http://127.0.0.1:8002/api/health; do sleep 3; done
docker compose ps --format '{{.Service}} {{.Image}}' | grep '^plausible '
curl -s -w ' %{http_code}\n' http://127.0.0.1:8002/api/healthSymptom: None – and that is exactly the problem.
plausible ghcr.io/plausible/community-edition:v3.1.0
{"sessions":"ok","postgres":"ok","clickhouse":"ok","sites_cache":"ok"} 200
Investigate:
# on argo
cd ~/plausible/probe
docker compose exec -T plausible_db psql -U postgres -d plausible_db \
-tAc "select count(*) from schema_migrations"Expected:
222
Cause: The old version runs on the new schema. Migrations only run forwards; v3.1.0 does not know the four new ones, so it leaves them in place. Nobody tests whether old code copes with new tables and columns – today it works, next time it might not.
Fix: The clean way back is the backup from before the upgrade (Challenge).
Save your progress? Sign up for free
Exercise: Speed Drills
- Show which Plausible version runs in the
cestack – according to the image and according to the branch. Target time: 30 s - Count Plausible’s
[error]lines from the last 10 minutes. Target time: 30 s
Solution
# on argo
cd ~/plausible/ce
docker compose ps --format '{{.Image}}' plausible
git branch --show-current || git describe --all
docker compose logs plausible --since 10m --no-log-prefix 2>&1 | grep -c '\[error\]'Expected (the number will differ):
ghcr.io/plausible/community-edition:v3.2.1
v3.2.1
0
Save your progress? Sign up for free
Checkpoint
# on argo
curl -s -o /dev/null -w '%{http_code}\n' https://plausible.lab/api/health
curl -s http://127.0.0.1:8025/api/v1/messages | jq '.total'
cd ~/plausible/ce && docker compose ps --format '{{.Service}}' | sort | tr '\n' ' '
echoExpected:
200
1
mailpit plausible plausible_db plausible_events_db
Challenge
Roll the trial stack back to v3.1.0 cleanly: with the PostgreSQL backup from before the upgrade, so that the migrations are back at 218 and the site is still there.
Hint: Stop Plausible, drop the database, restore
with --create (Day 8). ClickHouse does not need to go back
– the upgrade brought no migration there.
Solution
# on argo
cd ~/plausible/probe
docker compose stop plausible 2>&1 | tail -1
docker compose exec -T plausible_db psql -U postgres -q \
-c 'drop database plausible_db with (force)'
docker compose exec -T plausible_db pg_restore -U postgres --create -d postgres \
< ~/plausible/probe-vor-upgrade.dump
docker compose start plausible 2>&1 | tail -1
until curl -sf -o /dev/null http://127.0.0.1:8002/api/health; do sleep 3; done
docker compose exec -T plausible_db psql -U postgres -d plausible_db \
-tAc "select count(*) from schema_migrations; select domain from sites"Expected:
Container probe-plausible-1 Stopped
Container probe-plausible-1 Started
218
itdrills.com
Back at 218, the site is there. Had the upgrade also migrated ClickHouse, its backup would have to go back as well – that is why you back up both before every upgrade (Day 8).
Save your progress? Sign up for free
Cleanup
The trial stack is no longer needed. Mailpit stays in the
ce stack.
# on argo
cd ~/plausible/probe
docker compose down -v 2>&1 | tail -1
cd ~ && rm -rf ~/plausible/probe ~/plausible/probe-vor-upgrade.dump
docker volume ls --format '{{.Name}}' | grep -c '^probe_'Expected:
0
Interview Note
- How do you notice that Plausible is losing data?
/api/healthreports ClickHouse aserror, the log showsWriteBuffer terminating. The202response to events is deceptive – it only means “accepted”. - How does an upgrade of the Community Edition work? Back up
both databases, switch the branch,
docker compose up -d; the migrations run at startup. - Can you simply go back? No. Migrations only run forwards; the only clean way back is the backup from before.
Enterprise Note
- Monitoring on
/api/healthwith alerting, plus disk space and ClickHouse memory. An outage costs data, not just availability. - Upgrades first on a trial stack with a copy of the real data, then in a maintenance window: back up, switch over, compare numbers (Day 8, Drill 6).
- Read the release notes: some versions require a ClickHouse or PostgreSQL upgrade beforehand, and there are separate guides for that in the wiki of the CE repo.
- SMTP through a provider with SPF and DKIM for your own domain, otherwise invitations and reports end up in spam.