Skip to content

Instantly share code, notes, and snippets.

@samof76
Created September 14, 2024 03:47
Show Gist options
  • Select an option

  • Save samof76/8744ab377cd1142960f4e37039966441 to your computer and use it in GitHub Desktop.

Select an option

Save samof76/8744ab377cd1142960f4e37039966441 to your computer and use it in GitHub Desktop.

Revisions

  1. samof76 created this gist Sep 14, 2024.
    44 changes: 44 additions & 0 deletions ch_memory_high.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    To investigate high RAM usage in ClickHouse and determine what's consuming so much memory, you can try the following steps:

    1. Check system tables:
    Query the system.metrics and system.asynchronous_metrics tables to get an overview of memory usage:

    ```sql
    SELECT * FROM system.metrics WHERE metric LIKE '%Memory%';
    SELECT * FROM system.asynchronous_metrics WHERE metric LIKE '%Memory%';
    ```

    2. Examine query memory usage:
    Look at currently running queries and their memory consumption:

    ```sql
    SELECT query_id, user, elapsed, memory_usage
    FROM system.processes
    ORDER BY memory_usage DESC;
    ```

    3. Check table sizes:
    Identify large tables that might be causing memory pressure:

    ```sql
    SELECT database, name, total_bytes, total_rows
    FROM system.tables
    ORDER BY total_bytes DESC
    LIMIT 10;
    ```

    4. Review merge processes:
    Check if there are any large merges in progress:

    ```sql
    SELECT * FROM system.merges;
    ```

    5. Inspect background processes:
    Look at background processes that might be consuming memory:

    ```sql
    SELECT * FROM system.background_processing_pool;
    ```