> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for Apply patches from lightweight updates

# Apply patches from lightweight updates

export const galaxyOnClick = eventName => () => {
  try {
    if (typeof window !== "undefined" && window.galaxy && eventName) {
      window.galaxy.track(eventName, {
        interaction: "click"
      });
    }
  } catch (e) {}
};

export const BetaBadge = ({link, galaxyTrack, galaxyEvent}) => {
  if (link) {
    return <a href={link} target="_blank" rel="noopener noreferrer" className="betaBadge" onClick={galaxyTrack && galaxyEvent ? galaxyOnClick(galaxyEvent) : undefined}>
                <Icon />
                <span>Beta</span>
            </a>;
  }
  return <div className="betaBadge">
            <Icon />
            <span>
                Beta feature. 
                <u>
                    <a href="/docs/beta-and-experimental-features#beta-features">
                        Learn more.
                    </a>
                </u>
            </span>
        </div>;
};

```sql theme={null}
ALTER TABLE [db.]table [ON CLUSTER cluster] APPLY PATCHES [IN PARTITION partition_id]
```

The command manually triggers the physical materialization of patch parts created by [lightweight `UPDATE`](/reference/statements/update) statements. It forcefully applies pending patches to the data parts by rewriting only the affected columns.

<Note>
  * It only works for tables in the [`MergeTree`](/reference/engines/table-engines/mergetree-family/mergetree) family (including [replicated](/reference/engines/table-engines/mergetree-family/replication) tables).
  * This is a mutation operation and executes asynchronously in the background.
</Note>

<h2 id="when-to-use">
  When to use APPLY PATCHES
</h2>

<Tip>
  Generally, you should not need to use `APPLY PATCHES`
</Tip>

Patch parts are normally applied automatically during merges when the [`apply_patches_on_merge`](/reference/settings/merge-tree-settings#apply_patches_on_merge) setting is enabled (default). However, you may want to manually trigger patch application in these scenarios:

* To reduce the overhead of applying patches during `SELECT` queries
* To consolidate multiple patch parts before they accumulate
* To prepare data for backup or export with patches already materialized
* When `apply_patches_on_merge` is disabled and you want to control when patches are applied

<h2 id="examples">
  Examples
</h2>

Apply all pending patches for a table:

```sql theme={null}
ALTER TABLE my_table APPLY PATCHES;
```

Apply patches only for a specific partition:

```sql theme={null}
ALTER TABLE my_table APPLY PATCHES IN PARTITION '2024-01';
```

Combine with other operations:

```sql theme={null}
ALTER TABLE my_table APPLY PATCHES, UPDATE column = value WHERE condition;
```

<h2 id="monitor">
  Monitoring patch application
</h2>

You can monitor the progress of patch application using the [`system.mutations`](/reference/system-tables/mutations) table:

```sql theme={null}
SELECT * FROM system.mutations
WHERE table = 'my_table' AND command LIKE '%APPLY PATCHES%';
```

<h2 id="see-also">
  See also
</h2>

* [Lightweight `UPDATE`](/reference/statements/update) - Create patch parts with lightweight updates
* [`apply_patches_on_merge` setting](/reference/settings/merge-tree-settings#apply_patches_on_merge) - Control automatic patch application during merges
