Skip to content

Commit 622d496

Browse files
Enhance documentation on detached parts in ClickHouse
Added details about detached parts, including recovery, cleanup, and the DROP DETACHED command in ClickHouse.
1 parent 19b8822 commit 622d496

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

content/en/altinity-kb-useful-queries/detached-parts.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ keywords:
99
- clickhouse drop partition
1010
---
1111

12+
Detached parts act like the “Recycle Bin” in Windows. When ClickHouse deems some data unneeded—often during internal reconciliations at server startup—it moves the data to the detached area instead of deleting it immediately.
13+
14+
Recovery: If you’re missing data due to misconfiguration or an error (such as connecting to the wrong ZooKeeper), check the detached parts. The missing data might be recoverable through manual intervention.
15+
16+
Cleanup: Otherwise, clean up the detached parts periodically to free disk space.
17+
18+
Regarding detached parts and the absence of an automatic cleanup feature within ClickHouse: this was a deliberate decision, as there is a possibility that data may appear there due to a bug in ClickHouse's code, a hardware error (such as a memory error or disk failure), etc. In such cases, automatic cleanup is not desirable.
19+
1220
Blog article - https://altinity.com/blog/understanding-detached-parts-in-clickhouse
1321

22+
1423
ClickHouse® users should monitor for detached parts and act quickly when they appear. Here is what the different statuses of detached parts mean:
1524

1625
1. Parts are renamed to **ignored** if they were found during ATTACH together with other, bigger parts that cover the same blocks of data, i.e. they were already merged into something else.
@@ -38,6 +47,19 @@ GROUP BY database, table, reason
3847
ORDER BY database ASC, table ASC, reason ASC
3948
```
4049

50+
### drop detached
51+
The DROP DETACHED command in ClickHouse is used to remove parts or partitions that have previously been detached (i.e., moved to the detached directory and forgotten by the server). The syntax is:
52+
53+
```
54+
ALTER TABLE table_name [ON CLUSTER cluster] DROP DETACHED PARTITION|PART ALL|partition_expr
55+
```
56+
57+
This command removes the specified part or all parts of the specified partition from the detached directory. For more details on how to specify the partition expression, see the documentation on how to set the partition expression DROP DETACHED PARTITION|PART.
58+
59+
Note: You must have the allow_drop_detached setting enabled to use this command allow_drop_detached
60+
61+
### drop all script
62+
4163
Here is a query that can help with investigations. It looks for active parts containing the same data blocks as the detached parts. It
4264
generates commands to drop the detached parts.
4365

@@ -77,12 +99,3 @@ covered-by-broken - that means that ClickHouse during initialization of replica
7799

78100
The list of DETACH_REASONS: https://github.com/ClickHouse/ClickHouse/blob/master/src/Storages/MergeTree/MergeTreePartInfo.h#L163
79101

80-
## More notes on ClickHouseDetachedParts
81-
82-
Detached parts act like the “Recycle Bin” in Windows. When ClickHouse deems some data unneeded—often during internal reconciliations at server startup—it moves the data to the detached area instead of deleting it immediately.
83-
84-
Recovery: If you’re missing data due to misconfiguration or an error (such as connecting to the wrong ZooKeeper), check the detached parts. The missing data might be recoverable through manual intervention.
85-
86-
Cleanup: Otherwise, clean up the detached parts periodically to free disk space.
87-
88-
Regarding detached parts and the absence of an automatic cleanup feature within ClickHouse: this was a deliberate decision, as there is a possibility that data may appear there due to a bug in ClickHouse's code, a hardware error (such as a memory error or disk failure), etc. In such cases, automatic cleanup is not desirable.

0 commit comments

Comments
 (0)