NEW

Pulse 2025 Product Roundup: From Monitoring to AI-Native Control Plane

ClickHouse DB::Exception: Broken projection

The "DB::Exception: Broken projection" error in ClickHouse indicates that the data for a projection within one or more table parts is corrupted or inconsistent with the base data. This can result from disk errors, incomplete writes, or interrupted merge operations. The error code is BROKEN_PROJECTION.

Impact

When ClickHouse detects a broken projection, it may refuse to use that projection for query optimization or may fail when attempting to read parts containing the corrupted projection. Depending on the check_table_dependencies and other settings, this could affect inserts or merges that involve the affected parts. The base table data itself is typically not corrupted -- only the projection data is broken.

Common Causes

  1. Disk errors or hardware failures -- bad sectors or I/O errors during write can corrupt projection files.
  2. Server crash during merge or insert -- if the server terminates unexpectedly while writing projection data, the result may be incomplete.
  3. Manual modification of data files -- directly editing files in the ClickHouse data directory can corrupt projections.
  4. Out-of-disk-space during write -- insufficient disk space can lead to partially written projection data.
  5. Bug in a specific ClickHouse version -- certain releases have had bugs related to projection maintenance during merges.

Troubleshooting and Resolution Steps

  1. Identify the broken projection and affected parts:

    -- Check for parts with broken projections
    SELECT name, active, rows_count, modification_time
    FROM system.parts
    WHERE database = 'default'
      AND table = 'your_table'
      AND has_broken_projections = 1;
    
  2. Clear the broken projection to rebuild it:

    -- Clear the projection data from all parts
    ALTER TABLE your_table CLEAR PROJECTION projection_name;
    
    -- Re-materialize the projection
    ALTER TABLE your_table MATERIALIZE PROJECTION projection_name;
    
  3. If clearing does not work, drop and re-add the projection:

    ALTER TABLE your_table DROP PROJECTION projection_name;
    
    ALTER TABLE your_table ADD PROJECTION projection_name (
        SELECT * ORDER BY some_column
    );
    
    ALTER TABLE your_table MATERIALIZE PROJECTION projection_name;
    
  4. Run a table check to identify other issues:

    CHECK TABLE your_table;
    
  5. Check disk health and available space:

    df -h /var/lib/clickhouse
    dmesg | grep -i 'error\|i/o\|disk'
    
  6. Review server logs around the time the corruption occurred:

    grep -i 'projection\|broken\|corrupt' /var/log/clickhouse-server/clickhouse-server.log | tail -50
    

Best Practices

  • Monitor disk health and free space on ClickHouse data volumes to prevent write failures.
  • Use RAID or redundant storage to protect against single-disk failures.
  • Keep ClickHouse updated to benefit from bug fixes related to projection handling.
  • For replicated tables, verify that the projection is healthy on all replicas -- corruption on one replica does not necessarily affect others.
  • Periodically run CHECK TABLE on important tables to detect corruption early.
  • Consider using fewer projections on tables with very high write throughput, as each projection adds write complexity and risk.

Frequently Asked Questions

Q: Does a broken projection mean my data is lost?
A: No. Projections are derived data structures computed from the base table data. The base data is stored independently. You can always drop and re-create the projection without any data loss.

Q: Will ClickHouse automatically skip broken projections during queries?
A: In many cases, yes. ClickHouse can fall back to reading the base table data if a projection is broken. However, depending on the version and settings, some operations may fail. Clearing and re-materializing the projection is the recommended fix.

Q: Can a broken projection cause insert failures?
A: Potentially, if the insert triggers a merge of parts that include a broken projection. The merge may fail, which can temporarily block inserts. Clearing the broken projection resolves this.

Q: How do I prevent projection corruption?
A: Ensure stable disk I/O, sufficient free space, and graceful server shutdowns. Use a UPS or reliable infrastructure to prevent power-related crashes during writes.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.

We use cookies to provide an optimized user experience and understand our traffic. To learn more, read our use of cookies; otherwise, please choose 'Accept Cookies' to continue using our website.