# Online Patching the `TiDB` Cluster

__*TiDB patch upgrade*__
__*TiUP hotfix*__
__*tiup cluster patch*__

+ Syntax and examples

+ **Example 1:** Patch all `TiDB` instances for a cluster

+ **Example 2:** Patch one instance within a `TiDB` cluster

+ **Example 3:** Patch one instance and make the patch version the default version for future scaling out operations. (After you patch a certain component, such as TiDB or TiKV, when the tiup cluster scales out the component, TiUP uses the original component version by default.)

```
~!@// Example 1@!~
$ tiup cluster patch cluster1 /tmp/tidb-v6.1.1-linux-amd64.tar.gz --role tidb

~!@// Example 2@!~
$ tiup cluster patch cluster1 /tmp/tidb-v6.1.1-linux-amd64.tar.gz --node 10.0.0.138:4000

~!@// Example 3@!~
$ tiup cluster patch cluster1 /tmp/tidb-v6.1.1-linux-amd64.tar.gz --node 10.0.0.138:4000 ~!@--overwrite@!~
```

-------------------------------------------------------------
You can use `tiup cluster patch` command to dynamically replace the binaries of a service while the cluster is running (namely, keep the cluster available during the replacement process). The `patch` command does the following:
- Uploads the binary package for replacement to the target machine.
- If the target service is a storage service such as `TiKV`, `TiFlash`, or `TiDB Binlog`, `TiUP` first takes the related nodes offline via the `API`.
- Stops the target service.
- Unpacks the binary package and replace the service.
- Starts the target service.

Usage:
```
  tiup cluster patch {cluster_name} {package_path} [flags]
```

Flags:
```
  -h, --help                    help for patch
  -N, --node strings            Specify the nodes
      --offline                 Patch a stopped cluster
      --overwrite               Use this package in the future scale-out operations
  -R, --role strings            Specify the roles
      --transfer-timeout uint   Timeout in seconds when transferring PD and TiKV store leaders, also for TiCDC drain one capture (default 600)
```
Global Flags:
```
  -c, --concurrency int     max number of parallel tasks allowed (default 5)
      --ssh-timeout uint    Timeout in seconds to connect host via SSH, ignored for operations that don't need an SSH connection. (default 5)
      --wait-timeout uint   Timeout in seconds to wait for an operation to complete, ignored for operations that don't fit. (default 120)
  -y, --yes                 Skip all confirmations and assumes 'yes'
```