# Online Scale in (TiFlash)

__*TiDB online scale in*__
__*TiFlash online scale in*__

+ Step 1: Adjust the number of replica of the data table according to the number of remaining TiFlash nodes
  + `alter table <db-name>.<table-name> set tiflash replica 0;`

+ Step 2: Confirm that the replica of the table has been deleted
  + `SELECT * FROM information_schema.tiflash_replica WHERE TABLE_SCHEMA = '<db_name>' and TABLE_NAME = '<table_name>'`

+ Step 3: View the node ID information
  + `tiup cluster display <cluster-name>`

+ Step 4: Shrink TiFlash nodes with TiUP
  + `tiup cluster scale-in <cluster-name> --node <node-IP>:<node-Port>`

+ Step 5: Check the status of the cluster
  + `tiup cluster display <cluster-name>`

-------------------------------------------------------------

When removing TiFlash, ensure that the number of remaining nodes in the TiFlash cluster is greater than or equal to the maximum number of replicas of all data tables. Otherwise, you need to modify the TiFlash replica count of the related table. That is, you need to clean up the replica on the TiFlash that you want to remove. Let's say we need to remove a TiFlash node with an IP address of 10.0.1.4.

Step 1: Adjust the number of replica of the data table according to the number of remaining TiFlash nodes
ALTER TABLE<db-name>. <table-name>set tiflash replica 0;
The purpose of this step is to clean up the replica of the table on the TiFlash node that will be removed.

Step 2: Confirm that the replica of the table is indeed deleted
SELECT * FROM Information*schema.tiflash*Replica WHERE Table*SCHEMA = '<db*Name>' and Table*NAME = '<table*Name>'
The related table could not be found in the result set indicating that the replica was deleted.

Step 3: View the node ID information
tiup cluster display <cluster-name>
Based on the output, confirm the nodes you want to remove.

Step 4: Shrink TiFlash nodes with TiUP
tiup cluster scale-in <cluster-name>—node<node-IP>: <node-Port>
The —node parameter is the ID of the node that needs to be offline.
Scaled cluster <cluster-name>in scaling information is expected to be output, indicating that scale in operation was successful.

Step 5: Check the status of the cluster
Execute the following command to check if the node went offline successfully:
tiup cluster display <cluster-name>

Please refer to the documentation: https://docs.pingcap.com/zh/tidb/stable/scale-tidb-using-tiup



