## Module 4: Cleanup

Whether the lab ends or times out, all data on the virtual machine is automatically destroyed. Files on TiDB Cloud Filesystem and data in TiDB Cloud Starter are not.

This module has two parts. If you want to keep the free TiDB Cloud resources you created, see **Keep and Start Free**. If you do not want to keep them, skip ahead to the **Cleanup** section.

### Keep and Start Free

TiDB Cloud Filesystem free policy: exceeding the free quota blocks writes but not reads. Credit-card accounts are exempt from these limits:

- Each TiDB Cloud region can have up to 2 free file systems. (Current region list: aws-us-east-1, aws-us-west-2, aws-ap-southeast-1)
- Free file systems in each region can store up to 2000 files.
- Free file systems in each region can store up to 2GB of usage in total.
- A single file in a free file system cannot exceed 500 MB.

For your TiDB Cloud API Key, you can go to [https://tidbcloud.com/org-settings/api-keys](https://tidbcloud.com/org-settings/api-keys) at any time to delete an existing key or generate a new key pair.

- The `fs_token` for the `lab-workspace` TiDB Cloud file system created in this lab can be rotated or managed at any time with the **`ti`** CLI (with a TiDB Cloud API Key configured):
  - **`ti fs list-file-systems`**: List all file systems.
  - **`ti fs list-file-system-tokens`**: List all file system tokens.
  - **`ti fs disable-file-system-token`**: Disable a token.
  - **`ti fs delete-file-system-token`**: Delete a token.
  - **`ti fs generate-file-system-token`**: Generate a new token.

- The `DATABASE_URL` (including credentials) for the TiDB Cloud Starter instance created in this lab can also be regenerated at any time with the **`ti`** CLI (with a TiDB Cloud API Key configured):
  - **`ti db list-db-clusters --db-cluster-type starter`**: List all Starter clusters.
  - **`ti db create-db-sql-users`**: Create SQL users for a Starter cluster.
  - **`ti db format-db-connection-string`**: Get the `DATABASE_URL` (including credentials) for a specified role.

### Cleanup

- Stay in **[Terminal 2](ssh://monitor1-ssh#2)**.

- Delete the TiDB Cloud Starter database cluster:

> [!CAUTION]
> All data stored in `hermes-data` will be permanently deleted.

```bash
# Find the TiDB Cloud Starter cluster named `hermes-data`
read DB_CLUSTER_ID <<< "$(ti db list-db-clusters \
  --db-cluster-type starter \
  --query "clusters[?display_name=='hermes-data'].id" \
  --region aws-${LAB:REGION_CODE} \
  --output text \
  )"

# Delete the found TiDB Cloud Starter cluster
ti db delete-db-cluster \
  --db-cluster-id $DB_CLUSTER_ID

unset DB_CLUSTER_ID
```

- Delete the TiDB Cloud file system instance:

> [!CAUTION]
> All data stored in the `lab-workspace` file system will be permanently deleted.

```bash
# Find the TiDB Cloud file system instance named `lab-workspace`
read FS_ID <<< "$(ti fs list-file-systems \
  --query "file_systems[?display_name=='lab-workspace'].file_system_id" \
  --region aws-${LAB:REGION_CODE} \
  --output text \
  )"

# Delete the found TiDB Cloud file system instance
ti fs delete-file-system --file-system-id $FS_ID --region aws-${LAB:REGION_CODE}

unset FS_ID
```
