> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Resolving "Table or Partition was not dropped: Size is greater than max_[table/partition]_size_to_drop"

> Why ClickHouse refuses to drop or truncate a large MergeTree table or partition with error 359, and how to lift the limit for one query, for the server, or with a flag file.

ClickHouse refuses to drop a `MergeTree` table or partition that is larger than a size limit, to protect you from deleting a lot of data by mistake. If you do want to drop it, pass the limit with the query: add `SETTINGS max_table_size_to_drop = 0` to `DROP TABLE`, or `SETTINGS max_partition_size_to_drop = 0` to `ALTER TABLE ... DROP PARTITION`. The value `0` removes the limit.

## The error

```text theme={null}
Code: 359. DB::Exception: Table or Partition in db.events was not dropped.
Reason:
1. Size (24.23 MB) is greater than max_[table/partition]_size_to_drop (1.00 MB)
2. File '/var/lib/clickhouse/flags/force_drop_table' intended to force DROP doesn't exist
How to fix this:
1. Either increase (or set to zero) max_[table/partition]_size_to_drop in server config
2. Either pass a bigger (or set to zero) max_[table/partition]_size_to_drop through query settings
3. Either create forcing file /var/lib/clickhouse/flags/force_drop_table and make sure that ClickHouse has write permission for it.
Example:
sudo touch '/var/lib/clickhouse/flags/force_drop_table' && sudo chmod 666 '/var/lib/clickhouse/flags/force_drop_table'. (TABLE_SIZE_EXCEEDS_MAX_DROP_SIZE_LIMIT)
```

The sizes in the message use decimal units, so the default limit is printed as `50.00 GB`.

## Which statements are checked

| Limit | Default | Compared with | Statements |
| - | - | - | - |
| `max_table_size_to_drop` | 50 GB (`50000000000` bytes) | Size of all active parts of the table | `DROP TABLE`, `TRUNCATE TABLE`, `DROP DATABASE` (every table in it), `CREATE OR REPLACE TABLE` (the replaced table) |
| `max_partition_size_to_drop` | 50 GB (`50000000000` bytes) | Size of the partition or of the part | `ALTER TABLE ... DROP PARTITION`, `DETACH PARTITION`, `DROP PART`, `REPLACE PARTITION` |

Both limits exist as a server setting ([table](https://clickhouse.com/docs/reference/settings/server-settings/settings/max-table.md#max_table_size_to_drop), [partition](https://clickhouse.com/docs/reference/settings/server-settings/settings/max.md#max_partition_size_to_drop)) and as a query-level setting with the same name ([table](https://clickhouse.com/docs/reference/settings/session-settings/max.md#max_table_size_to_drop), [partition](https://clickhouse.com/docs/reference/settings/session-settings/max.md#max_partition_size_to_drop)). When the query-level setting is changed (in the query, in the session, or in a settings profile), it is used instead of the server setting, whether it is larger or smaller.

In ClickHouse Cloud the default is 1 TB, see [`max_table_size_to_drop`](https://clickhouse.com/docs/products/cloud/guides/cloud-compatibility#max_table_size_to_drop-1000000000000).

## Example

To reproduce the error without creating 50 GB of data, this example lowers both limits to 1 MB for the session:

```sql theme={null}
CREATE DATABASE db;

CREATE TABLE db.events
(
    event_date Date,
    id UInt64,
    payload String
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(event_date)
ORDER BY id;

INSERT INTO db.events
SELECT
    toDate('2026-01-01') + number % 90,
    number,
    toString(cityHash64(number))
FROM numbers(1000000);

SET max_table_size_to_drop = 1000000, max_partition_size_to_drop = 1000000;

DROP TABLE db.events;
```

The `DROP TABLE` fails with the error shown above. Check how large the partitions are:

```sql theme={null}
SELECT
    partition,
    count() AS parts,
    formatReadableSize(sum(bytes_on_disk)) AS size
FROM system.parts
WHERE database = 'db' AND table = 'events' AND active
GROUP BY partition
ORDER BY partition;
```

```text theme={null}
   ┌─partition─┬─parts─┬─size─────┐
1. │ 202601    │     1 │ 7.96 MiB │
2. │ 202602    │     1 │ 7.19 MiB │
3. │ 202603    │     1 │ 7.96 MiB │
   └───────────┴───────┴──────────┘
```

Each partition is larger than `max_partition_size_to_drop`, so `ALTER TABLE db.events DROP PARTITION 202601` fails with the same error, reporting `Size (8.34 MB)`. With the limit passed in the query, the partition is dropped:

```sql theme={null}
ALTER TABLE db.events DROP PARTITION 202601 SETTINGS max_partition_size_to_drop = 0;
```

## Ways to lift the limit

### For one query or session

Add `SETTINGS max_partition_size_to_drop = 0` or `SETTINGS max_table_size_to_drop = 0` to the statement, or run `SET` before it. Instead of `0` you can pass a value in bytes that is larger than the table. This is the way to do it in ClickHouse Cloud. The table-level setting works the same way for `TRUNCATE TABLE`, `DROP TABLE` and `DROP DATABASE`:

```sql theme={null}
TRUNCATE TABLE db.events SETTINGS max_table_size_to_drop = 0;

DROP TABLE db.events SETTINGS max_table_size_to_drop = 0;
```

The query-level settings are available since ClickHouse 23.12.

### For the whole server

On a self-managed server, set the limits at the top level of the server configuration. The change is applied without a restart:

```xml theme={null}
<clickhouse>
    <max_table_size_to_drop>0</max_table_size_to_drop>
    <max_partition_size_to_drop>0</max_partition_size_to_drop>
</clickhouse>
```

### For one drop, with a flag file

On a self-managed server you can create the file named in the error message. ClickHouse deletes the file when it allows a drop, so the file permits exactly one statement and you have to create it again for the next one:

```bash theme={null}
sudo touch '/var/lib/clickhouse/flags/force_drop_table' && sudo chmod 666 '/var/lib/clickhouse/flags/force_drop_table'
```

The directory is `flags` inside the ClickHouse data path, so use the path printed in your error message.

### Without lifting the limit

If the table is larger than `max_table_size_to_drop` but every partition is smaller than `max_partition_size_to_drop`, you can drop the partitions one by one with [`ALTER TABLE ... DROP PARTITION`](https://clickhouse.com/docs/reference/statements/alter/partition#drop-partitionpart) and then drop the empty table. Use the query on `system.parts` above to list the partitions and their sizes.

## Materialized views

A materialized view created without a `TO` clause stores its data in a hidden inner table, and dropping the view drops that table. If the inner table is larger than the limit, the error names the inner table:

```sql theme={null}
CREATE TABLE db.src (id UInt64, payload String) ENGINE = MergeTree ORDER BY id;

CREATE MATERIALIZED VIEW db.events_mv ENGINE = MergeTree ORDER BY id AS SELECT id, payload FROM db.src;

INSERT INTO db.src SELECT number, toString(cityHash64(number)) FROM numbers(1000000);

DROP VIEW db.events_mv;
```

```text theme={null}
Code: 359. DB::Exception: Table or Partition in db.`.inner_id.e86282b9-3af3-42e5-8db2-a1f22dbae1c3` was not dropped.
Reason:
1. Size (24.19 MB) is greater than max_[table/partition]_size_to_drop (1.00 MB)
...
```

Pass the setting when you drop the view:

```sql theme={null}
DROP VIEW db.events_mv SETTINGS max_table_size_to_drop = 0;
```

The handling of the size limits for inner tables was fixed in ClickHouse 25.11. If the statement above still fails on an older release, first run `DROP TABLE ... SETTINGS max_table_size_to_drop = 0` for the inner table, with the name copied from the error message and quoted with backticks, and then drop the view.
