> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 删除工作空间

<Note>
  删除工作空间的功能在 **LangSmith 自托管版本 v0.10 中已原生支持**。请查看[删除工作空间的说明](/langsmith/set-up-hierarchy#delete-a-workspace)。

  对于 v0.10 之前的自托管版本，请遵循以下指南。
</Note>

LangSmith UI 目前不支持从组织中删除单个工作空间。但是，可以通过直接从 ClickHouse 中所有物化视图（runs\_history 视图除外）以及 runs 和 feedbacks 表中移除所有跟踪数据，然后从 Postgres 的 tenants 表中移除该工作空间来实现。

此命令使用工作空间 ID 作为参数。

### 前提条件

确保您已准备好以下工具/项目。

1. kubectl

   * [https://kubernetes.io/docs/tasks/tools/](https://kubernetes.io/docs/tasks/tools/)

2. PostgreSQL 客户端

   * [https://www.postgresql.org/download/](https://www.postgresql.org/download/)

3. PostgreSQL 数据库连接：

   * 主机
   * 端口
   * 用户名
     * 如果使用捆绑版本，此值为 `postgres`
   * 密码
     * 如果使用捆绑版本，此值为 `postgres`
   * 数据库名称
     * 如果使用捆绑版本，此值为 `postgres`

4. Clickhouse 数据库凭据

   * 主机
   * 端口
   * 用户名
     * 如果使用捆绑版本，此值为 `default`
   * 密码
     * 如果使用捆绑版本，此值为 `password`
   * 数据库名称
     * 如果使用捆绑版本，此值为 `default`

5. 从您将运行迁移脚本的机器连接到 PostgreSQL 数据库。

   * 如果您使用捆绑版本，可能需要将 postgresql 服务端口转发到您的本地机器。
   * 运行 `kubectl port-forward svc/langsmith-postgres 5432:5432` 将 postgresql 服务端口转发到您的本地机器。

6. 从您将运行迁移脚本的机器连接到 Clickhouse 数据库。

   * 如果您使用捆绑版本，可能需要将 clickhouse 服务端口转发到您的本地机器。
     * 运行 `kubectl port-forward svc/langsmith-clickhouse 8123:8123` 将 clickhouse 服务端口转发到您的本地机器。
   * 如果您使用 Clickhouse Cloud，则需要指定 --ssl 标志并使用端口 `8443`

7. 用于删除工作空间的脚本

   * 下载[工作空间脚本](https://github.com/langchain-ai/helm/blob/main/charts/langsmith/scripts/delete_workspace.sh)

### 运行单个工作空间的删除脚本

运行以下命令来执行工作空间移除脚本：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
sh delete_workspace.sh <postgres_url> <clickhouse_url> --workspace_id <workspace_id>
```

例如，如果您使用捆绑版本并进行了端口转发，命令将如下所示：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
sh delete_workspace.sh "postgres://postgres:postgres@localhost:5432/postgres" "clickhouse://default:password@localhost:8123/default" --workspace_id 4ec70ec7-0808-416a-b836-7100aeec934b
```

如果您访问 LangSmith UI，现在应该看到工作空间已被删除。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/langsmith/script-delete-a-workspace.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
