Skip to content

Commit

Permalink
Add guide on debugging memory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
justindeguzman committed Sep 20, 2023
1 parent ef5f627 commit 4c4d6a3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/en/guides/developer/debugging-memory-issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
slug: /en/guides/developer/debugging-memory-issues
sidebar_label: Debugging Memory Issues
sidebar_position: 1
description: Queries to help you debug memory issues.
---

# Debugging memory issues

When encountering memory issues, it is helpful to know what queries and resources are consuming a significant amount of memory. Below are queries that can help find which queries, databases, and tables can be optimized:

**List queries by peak memory usage**

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

**List metrics based on total memory usage**

```sql
SELECT
metric, description, formatReadableSize(value) size
FROM
system.asynchronous_metrics
WHERE
metric like '%Cach%'
or metric like '%Mem%'
order by
value desc;
```

**List databases by current memory usage**

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

**List merges by current memory usage**

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

**List processes by current memory usage**

```sql
SELECT formatReadableSize(sum(memory_usage)) FROM system.processes;
```
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const sidebars = {
'en/guides/developer/cascading-materialized-views',
'en/guides/developer/ttl',
'en/guides/developer/deduplication',
'en/guides/developer/debugging-memory-issues',
'en/sql-reference/dictionaries/index',
'en/guides/developer/lightweight-update',
'en/guides/developer/lightweight-delete',
Expand Down

0 comments on commit 4c4d6a3

Please sign in to comment.