跳至主要内容
跳至主要内容
编辑此页

调试内存问题

在遇到内存问题或内存泄漏时,了解哪些查询和资源正在消耗大量内存很有帮助。以下是一些可以帮助您通过查找可以优化的查询、数据库和表来调试内存问题的查询

按峰值内存使用量列出当前运行的进程

SELECT
    initial_query_id,
    query,
    elapsed,
    formatReadableSize(memory_usage),
    formatReadableSize(peak_memory_usage),
FROM system.processes
ORDER BY peak_memory_usage DESC
LIMIT 100;

列出内存使用情况的指标

SELECT
    metric, description, formatReadableSize(value) size
FROM
    system.asynchronous_metrics
WHERE
    metric LIKE '%Cach%'
    OR metric LIKE '%Mem%'
ORDER BY
    value DESC;

按当前内存使用量列出表

SELECT
    database,
    name,
    formatReadableSize(total_bytes)
FROM system.tables
WHERE engine IN ('Memory','Set','Join');

输出合并使用的总内存

SELECT formatReadableSize(sum(memory_usage)) FROM system.merges;

输出当前运行的进程使用的总内存

SELECT formatReadableSize(sum(memory_usage)) FROM system.processes;

输出字典使用的总内存

SELECT formatReadableSize(sum(bytes_allocated)) FROM system.dictionaries;

输出主键和索引粒度使用的总内存

SELECT
    sumIf(data_uncompressed_bytes, part_type = 'InMemory') AS memory_parts,
    formatReadableSize(sum(primary_key_bytes_in_memory)) AS primary_key_bytes_in_memory,
    formatReadableSize(sum(primary_key_bytes_in_memory_allocated)) AS primary_key_bytes_in_memory_allocated,
    formatReadableSize(sum(index_granularity_bytes_in_memory)) AS index_granularity_bytes_in_memory,
    formatReadableSize(sum(index_granularity_bytes_in_memory_allocated)) AS index_granularity_bytes_in_memory_allocated
FROM system.parts;
    © . This site is unofficial and not affiliated with ClickHouse, Inc.