Recovering from failed ClickHouse migrations in self-hosted Langfuse

A failed ClickHouse migration can leave a self-hosted Langfuse stuck in a dirty state. This page explains how to find out what partly applied, set the correct version and rerun migrations without damaging data.

On this page

Why a failed ClickHouse migration in Langfuse needs a controlled recovery

When a self-hosted Langfuse web or worker container fails at startup after a migration error, the instance will not come up, and the cause is often a ClickHouse schema change that stopped partway through. Langfuse applies database migrations automatically at startup for updates within a major version, so the failure can happen on a routine update, not only during a major upgrade. Because ClickHouse does not wrap a multi-step schema change in a single transaction the way PostgreSQL does, a migration that stops midway can leave some tables, columns or materialized views changed and others untouched. Restarting the container and hoping the next attempt succeeds is the most common mistake, because the migration tool may record the attempt as incomplete and refuse to proceed or repeat steps that already ran.

This page is for the operator who has just hit that state, usually after a failed update or a major upgrade such as the v3 to v4 path. Before touching anything, confirm the Langfuse version you were running, the version you were moving to, and the ClickHouse version in place, since the v4 guide sets minimum ClickHouse, PostgreSQL and Redis versions that must already be met. Check which migration the logs report as failing and whether any data backfill was in progress, because a backfill has its own disk and time demands. Take a ClickHouse backup or confirm that a recent one is restorable before making any manual change, so that a bad recovery step has a known way back.

The rest of this page covers how to determine how far the migration got, how to set the migration state to the version that matches the actual schema, and how to rerun migrations safely once the schema and the recorded state agree. Treat every manual step as a schema change that needs review by the person who owns the ClickHouse cluster. The Langfuse upgrade guide is the next read for the official migration sequence and for the version-specific steps that apply to your upgrade path.

How the recovery decision path flows from failure to rerun

The path starts when the Langfuse web or worker container fails to start after a ClickHouse migration error, which is the signal to stop and not retry blindly. Operators back up state first, then inspect ClickHouse and the migration records to judge whether the change fully applied, partly applied or never applied. Only that judgment decides whether to force the correct version or roll back, so the rerun happens from a known state. The final check confirms that the instance starts cleanly and that trace ingestion works again.

Decision path from a failed ClickHouse migration to a verified rerun.

How Langfuse applies ClickHouse migrations at startup

Within a major version, Langfuse applies its database migrations automatically when the application starts, so a migration failure usually surfaces as a container that does not come up cleanly rather than as a separate maintenance step you ran yourself. Langfuse says updates within a major version are non-disruptive, but that promise assumes the migrations complete. Major upgrades such as v1 to v2, v2 to v3 and v3 to v4 are different: they change infrastructure and the data model, and they follow dedicated migration guides. Start from the guide for your target version, not from the migration logs alone. The v3 to v4 guide, for example, sets minimum ClickHouse, PostgreSQL and Redis versions and moves to an observations-first ClickHouse data model, so a failed step there may belong to a planned backfill rather than to a routine schema change.

A clean failure is easier to handle than a partial one. If a migration fails before it changes anything, a retry on the same version is normally enough once the cause, such as a connectivity problem or insufficient permissions, is fixed. A partly applied change is harder to reason about because the schema may now contain some new tables, columns or indexes while the migration record still shows the step as incomplete or unrecorded. Retrying blindly can then fail on objects that already exist, or worse, appear to succeed while leaving the schema in an inconsistent state. Before you change anything, capture the current ClickHouse schema and the migration state table you find in the database, and compare them with the expected schema for your version.

Confirm in the release notes for your exact version how Langfuse tracks migration state, which tooling records it, and whether that record lives in ClickHouse, PostgreSQL or both. The release notes and upgrade guide for your version are the authority here, not assumptions carried over from an earlier release. Also confirm whether the migration tooling supports a documented way to mark a version as applied or to rerun a single step, and what the vendor advises before using it. Ask the vendor if the answer is unclear. Record what you confirmed in your runbook, because the steps you take in the next section depend on it.

How to determine whether a ClickHouse migration partly applied

This sequence freezes the instance, protects both data stores, and compares what Langfuse recorded as applied with the schema that actually exists in ClickHouse, so you can classify the failed migration before changing anything.

  1. Record the exact version and container logs

    Before touching anything, the operator on call copies the running Langfuse Web and Langfuse Worker image tags and the version of the ClickHouse and PostgreSQL servers, then saves the container logs from the last startup attempt that reported the migration error. Confirm the image tag against the release you deployed, not the one you intended to deploy. The step is done when you hold a dated file with the image tags, server versions and the full error text, because the error message usually names the migration file that failed.

  2. Stop the web and worker writers

    Scale or stop the Langfuse Web and Langfuse Worker containers so nothing writes to ClickHouse while you inspect it. In Kubernetes this means scaling both deployments to zero replicas; in Docker Compose it means stopping those two services and leaving ClickHouse, PostgreSQL and Redis or Valkey running. Keep the ingestion path in mind: SDK requests will fail or queue while the application is down, so tell the owners of the applications sending traces. The step is done when no Langfuse application pods or containers are running and the ClickHouse query log shows no new inserts from them.

  3. Back up ClickHouse and PostgreSQL

    Take a backup of ClickHouse and of the PostgreSQL database before any schema change, using the backup method your team already tests for each store. The PostgreSQL database holds the Prisma migration record that Langfuse uses to decide what to run next, and the ClickHouse data holds the tables a partial migration may have altered. Store both backups outside the cluster and confirm that the ClickHouse backup has enough free disk, since a later backfill can need substantially more headroom. The step is done when each backup has completed without errors and you have restored at least one of them to a scratch environment or verified its file list.

  4. Read the recorded migration state

    Query the migration history that Langfuse recorded in PostgreSQL and note the last migration marked as finished and any row that has a start time but no completion time. Also note the ClickHouse migration bookkeeping table if your Langfuse version uses one, and confirm the table name against the upgrade notes for your release. Write both lists down with their timestamps. The step is done when you can name the last migration Langfuse considers complete and whether an unfinished entry exists for the migration that failed.

  5. Inspect the schema actually present in ClickHouse

    Compare what the failed migration was meant to create or alter with what exists in ClickHouse. Read the migration file named in the error, list the tables, columns, indexes, materialized views and TTL settings it touches, then check each one with SHOW CREATE TABLE and by querying system.columns and system.tables in the Langfuse database. Look for objects that exist but are incomplete, such as a new table without its materialized view or a column added without its default. The step is done when you have a written checklist with each object marked present, absent or altered.

  6. Classify the migration as applied, partial or not applied

    Compare the recorded state from the migration history with the checklist from the schema inspection. Mark the migration fully applied when the recorded state shows it complete and every object exists as the migration file defines it. Mark it not applied when the history has no completed entry and none of its objects exist. Mark it partly applied when some objects exist, some are missing or altered, or the history shows an open entry with objects present. Ask the Langfuse maintainers or your upgrade guide for the expected end state if the migration file alone does not settle the question. The step is done when the classification and its evidence are written into the incident record and reviewed by a second engineer.

Which recovery path fits which failure state

This table matches the state you find in ClickHouse after a failed Langfuse migration to a recovery path, the risk each path carries and what to confirm first. Read it top to bottom, and stop at the first row that describes your state, because the cheaper paths only apply when the evidence supports them.

State foundRecovery pathRiskWhat to confirm first
Error was a network timeout or brief ClickHouse restart, and the schema looks completeWait for the automatic retry on restart, then confirm the migration table shows successLow, provided no partial DDL ranContainer logs show the error was connectivity, and ClickHouse is healthy and reachable from the web and worker containers
Migration row is marked dirty but the expected tables and columns are missing or only partly createdRestore from a verified backup taken before the upgrade, then rerun the migrationMedium, because restores replace current data written after the backupThe backup timestamp, whether any traces were ingested after it, and that the restore target matches the same ClickHouse version
Migration half-applied: some columns, tables or materialized views exist and others do notManually complete or reverse the partial change in a controlled session, then mark the version as appliedHigh, because a wrong manual statement can corrupt data or block later migrationsA written list of every object the failed statement touched, checked against the Langfuse migration source for your exact release
Schema looks complete but the recorded migration version does not match itCorrect the recorded version only after confirming the schema is what that version expectsMedium, because a wrong version mark makes later migrations skip or repeat workYour Langfuse release, the migration files it ships, and a schema comparison from a non-production copy
Backfill from the v3 to v4 upgrade stopped with disk nearly fullFree or add disk headroom, then resume or rerun the backfill rather than altering the schemaMedium, because a full disk can leave partial rows behindCurrent disk usage against the roughly 3x headroom the upgrade guide advises for backfilling historic data
Dirty state appeared after a Helm chart or database version mismatchFix the version prerequisite first, then restart so migrations rerun from the recorded stateLow to medium, because the mismatch may be the real cause and rerunning can repeat the failureClickHouse version against the 25.12 minimum in the upgrade guide, and Helm chart version against the v2 requirement
State is unclear, the cause is not in the logs, or a restore has already failedEscalate to Langfuse support or a qualified partner before running any further statementsHighest if you keep changing the database without a recordA snapshot of the schema, migration table and logs, plus the exact Langfuse and ClickHouse versions in use

When forcing the correct migration version is safe

Forcing a migration version is safe only when you have proven, table by table and object by object, that the schema matches the version you record. The main risk runs in two directions. If you mark a migration as applied while some of its changes are missing, Langfuse will skip it on later startups and the gap stays hidden until a query or write fails in production. If you rerun a migration that is not idempotent, for example one that creates an object or adds a column that already exists, the rerun can fail halfway through or change data a second time. Both outcomes are harder to undo than the original failure, so the decision to force a version should follow verification, never precede it.

Before you edit any recorded state by hand, confirm with the Langfuse documentation or the release notes for your exact version whether the failed migration can be rerun safely and what the migration state should look like afterwards. Check the upgrade guide for your path, including the Langfuse upgrade guide, and the release for the version you are on. Capture the current migration record, the ClickHouse table and column definitions the migration touches, and a backup of the affected data before any change. Record the exact commands you plan to run so a reviewer can check them against the documentation.

Once you have that evidence, compare the live schema with what the migration should have produced. If every change is present, marking the version as applied matches reality. If some changes are missing and the migration is confirmed safe to rerun, rerun it rather than editing the record. If the migration is not idempotent and the schema is partly changed, treat the case as a recovery project with your database owner, and decide with your vendor support path or DeployOpen whether a restore from backup is the safer route. Confirm each decision in writing so the next upgrade does not inherit an undocumented state.

How to rerun migrations safely after recovery

This sequence takes a ClickHouse that has been repaired and returns the Langfuse migration state to a known good version, with each step checked before the next one starts. The result is a self-hosted Langfuse that starts cleanly, serves the UI and processes a test trace end to end.

  1. Confirm the blocking cause is fixed

    Before any restart, the operator confirms that the condition that failed the migration is gone, such as a dropped connection, a permissions error, a full disk or a table lock held by another process. Run a simple query against ClickHouse from the Langfuse network with the same credentials the web and worker containers use. Done means the query returns a result and the ClickHouse logs show no recurring errors from the failed statement.

  2. Check ClickHouse version and disk headroom

    Compare the running ClickHouse version with the requirement in the Langfuse v3 to v4 upgrade guide, which asks for ClickHouse 25.12 or later and recommends 26.4. Check free disk on the ClickHouse data volume and keep roughly 3x headroom for the data being backfilled, as the guide advises. If you are on Helm with bundled data stores, confirm the chart upgrade from v1 to v2 has already been made. Done means the version and disk figures are written down and meet the guide, and any gap is resolved before continuing.

  3. Back up the current state before rerunning

    Take a snapshot or backup of the ClickHouse data and the PostgreSQL database that holds the migration record, so a second failure can be rolled back to a known point. Record the current Langfuse image tag and the migration status shown in the database. Done means the backup completes and you can restore it to a scratch environment, or the team has confirmed the backup tooling in your environment works.

  4. Start one web instance to run migrations

    Scale langfuse-web to a single replica and start it with the target Langfuse version, so migrations run once and the logs stay readable. Keep the worker scaled down until migrations finish, since workers should not process events against a half-migrated schema. Done means the container starts and the logs show migration activity rather than an immediate exit.

  5. Watch migration logs to completion

    Follow the web container logs until every migration reports success and the application reports it is listening. If a migration fails again, stop, do not restart in a loop, and compare the failing statement with the ClickHouse logs. Confirm the migration record in PostgreSQL shows the expected latest version. Done means the logs show completion with no migration errors and the recorded version matches the release you deployed.

  6. Verify the UI and ingest a test trace

    Sign in to the Langfuse UI through your normal SSO or account path, then open a project. Send one trace from a test script using a dedicated test project and its keys, and confirm it appears in the UI. This checks the web path, the write path to ClickHouse and the project configuration together. Done means the test trace is visible with the expected input and output.

  7. Confirm worker processing and scale up

    Scale the worker deployment back up and confirm it picks up the test trace event, which shows the asynchronous path works after migration. Watch the worker logs for errors and check that the event queue drains. Once the single web instance and worker behave, scale langfuse-web to the replica count your deployment needs, and repeat the UI and test trace check on the scaled deployment. Done means the test trace is processed by the worker and the full deployment passes the same checks.

Security and data risks during migration recovery

Manual migration repair puts database credentials, trace data and schema-change rights in one place, often under time pressure. The cards below cover the controls to confirm before anyone runs a command against ClickHouse or PostgreSQL, and the evidence to keep afterward.

Credential handling for manual commands

Repair usually means connecting to ClickHouse and PostgreSQL with credentials that normally only the application uses. Check that these sessions use named, short-lived accounts, that passwords are not pasted into shell history, terminal logs or chat, and that the connection strings in your runbook point to a vault reference rather than a plain value. Confirm the exact account names and privileges with your own deployment before starting.

Access to backups holding trace data

A snapshot taken before a repair contains full prompts, completions and any personal data that reached the traces. Restoring it into a scratch environment copies that data into a second place with its own access path. Confirm who may create, mount or restore these backups, where they are stored, and that the scratch environment has the same access controls as production.

Limiting who can run schema changes

Only a small group should be able to change ClickHouse schema or edit the migration state table, since a wrong manual change can break ingestion for every project. Define who approves the repair, who executes it and who verifies it, and make sure these are different people where your change process requires it. Check that these roles are reflected in your database account privileges, not only in the runbook.

Audit trail of manual interventions

Shell sessions and ad hoc SQL leave little record unless you capture it. Record the start and end time of each session, the commands run, the migration version before and after, and the person who approved the change. Confirm that database query logs or your terminal session recording are enabled and retained long enough for your internal review and any external assessor who samples changes.

Network exposure of ClickHouse during repair

Repair work often needs direct access to ClickHouse ports that are normally reachable only from the Langfuse containers. Open access only from the bastion or workstation used for the repair, for the shortest practical window, and close it afterward. Confirm the ports and source ranges in your network policy or security groups, and check that the ClickHouse listener is not exposed beyond the cluster or VM network.

Encrypting backup copies

Backup copies made for a repair should be encrypted at rest and in transit, with keys managed separately from the data they protect. Confirm which encryption your storage provider applies, who holds the keys, and whether copies made to a local disk or workstation are removed after the repair. Unencrypted exports of trace tables are one of the most common ways repair work leaks data.

Questions teams ask before recovering a failed ClickHouse migration

How long does recovering a failed ClickHouse migration take?

The duration depends on what the migration did before it stopped and how large the affected tables are, so no fixed figure applies to every instance. Most of the time goes to checking which statements completed, confirming the table state by hand and rerunning the remaining steps in a safe order. A small instance with a failed early migration usually resolves faster than one that stopped partway through a backfill over years of trace data. Ask any partner for a duration only after they have reviewed your migration logs, current schema and ClickHouse disk usage, and ask them to state what would extend the work.

Can our own operators recover a failed ClickHouse migration without outside help?

A team with ClickHouse and PostgreSQL experience can often handle a clean, well-understood failure in-house, provided it reads the migration state and logs carefully before changing anything. The risk rises when the migration partly applied, when tables were altered by hand, or when the team has not rehearsed a restore. Self-hosted Langfuse uses the same codebase as Langfuse Cloud, so the upgrade and migration documentation applies directly. Decide in advance who can approve a forced migration version and who owns the rollback plan, because those decisions are harder to make during an incident.

What access, backups and maintenance window does the recovery need?

The work needs administrative access to the ClickHouse cluster, read access to the Langfuse web and worker logs, and access to the PostgreSQL database that records migration state. It also needs a verified backup of ClickHouse and PostgreSQL taken before any change, plus a maintenance window during which ingestion can be paused or queued. Confirm with your team how long ingestion can be held before trace loss becomes a concern, and whether your blob storage keeps the raw events needed to replay. Without a tested backup, the safest path is usually to stop and plan a restore, not to force a version.

What does restoring ClickHouse from backup cost in disk and time?

A restore needs free disk on the target ClickHouse nodes for the restored data plus working space for the restore itself, so the disk you need is set by your data volume, not by a fixed ratio. For the v4 data model, the Langfuse v3 to v4 guide advises about 3x ClickHouse disk headroom when backfilling historic data, which is a useful planning floor if you are moving to that version. Restore time scales with data size, network throughput to the backup target and how many tables you restore. Ask for the disk estimate and restore timing to be based on your measured backup size, not on a general figure.

When should we escalate a failed ClickHouse migration to the vendor or a partner?

Escalate as soon as the migration state is unclear, a rerun fails with a different error, or the team is unsure whether data has been dropped or duplicated. Other triggers include a failure during a major upgrade, any step that touches the observations-first data model, and any situation where production trace ingestion is stalled for longer than your agreed tolerance. Gather the Langfuse version, the ClickHouse version, the PostgreSQL version, the migration log and a schema dump before you escalate. Early escalation usually costs less than a forced change that has to be reversed.

Does a Langfuse support plan change how a migration recovery is handled?

The Self-Hosted Enterprise plan on the Langfuse pricing page adds a named support engineer, solutions architect access and a support SLA, which can shorten the path to a vendor answer on a stuck migration. It does not replace your own backups, change access rights in your infrastructure or remove the need for a maintenance window. Check the plan terms directly for the response times and scope it includes, since those are set by Langfuse and are not described here. Separately, DeployOpen offers ongoing support and upgrade retainers, and any recovery work is quoted from a written scope agreed before the work starts.

What should a quote for ClickHouse migration recovery include?

A useful quote lists the assessment, the recovery steps, the backup and restore verification, the retest and the handover notes as separate line items. Ask what is one-time work and what recurs, such as retainer support or upgrade reviews. Ask which components are in scope, including ClickHouse, PostgreSQL, Redis or Valkey and blob storage, and what is excluded. Ask for the assumptions behind the disk and time estimate, the access you will need to provide and what changes the price if the migration state is worse than the first review shows.

How to prevent the next failed migration

The most effective prevention is to make sure a failed migration can be reversed without guesswork. Before any Langfuse upgrade, take verified backups of both ClickHouse and PostgreSQL, and test the restore in a non-production copy. A backup that has never been restored tells you little about whether you can recover, so confirm that the restored instance starts, that Langfuse web and worker connect to it, and that recent traces and prompts are readable. Record the Langfuse version, ClickHouse version and PostgreSQL version you are running today, since the rollback path depends on them.

Next, check the prerequisites in the target version's migration guide against your actual environment. The v3 to v4 guide, for example, requires ClickHouse 25.12 or later (26.4 recommended), PostgreSQL 15 or later and Redis 7.0 or later, and advises about 3x ClickHouse disk headroom when backfilling historic data. Confirm these numbers against the guide for the version you plan to install, not against this page. If you run a Helm chart with bundled data stores, confirm the chart upgrade step is complete first. Pin the Langfuse image tag and chart version explicitly in your deployment manifests so that a restart or redeploy never pulls a different release than the one you tested.

Finally, schedule the upgrade in a window that leaves room to roll back, and write the rollback plan before the window opens. Decide in advance who can stop the rollout, what triggers a rollback, and how long you will wait for migrations to finish before escalating. Keep the Langfuse web and worker containers stopped or scaled down while you inspect a dirty migration state, so that no new writes arrive against a half-migrated schema. For the full upgrade procedure and the differences between minor and major releases, follow the separate upgrade planning guidance in this section group rather than repeating those steps here.

How DeployOpen scopes and delivers ClickHouse migration recovery

DeployOpen treats a dirty ClickHouse migration state as an incident with a written recovery plan, not a quick fix. We start by confirming what the migration history and the ClickHouse schema actually show, then agree the recovery steps, the backups required beforehand and the verification that proves the instance is healthy again.

How we scope

  • We confirm the Langfuse version, the ClickHouse version and the upgrade path in use before any change is planned.
  • The written scope names which migration state checks, backups and reruns are included for your instance.
  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.

How we build

  • We inspect the migration records and table state in a copy of your environment before touching production.
  • Forced version changes and migration reruns are applied only after a verified backup of ClickHouse and PostgreSQL.
  • Each recovery step is tested against the same checks used to confirm a healthy Langfuse web and worker startup.

How we hand over

  • You receive a written record of the migration state found, each action taken and the reason for it.
  • Runbook steps cover how to detect a dirty state, back up first and rerun migrations safely in your environment.
  • Your operators walk through the verification checks so they can repeat them during future upgrades.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers for your self-hosted Langfuse.
  • A retainer can cover re-checking the migration state before each Langfuse upgrade you plan.
  • Confirm with us during scoping which support hours, escalation paths and response terms apply to your agreement.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.