Documentation

管理 DBRP 映射

InfluxQL 需要数据库和保留策略 (DBRP) 组合才能查询数据。在 InfluxDB 2.7 中,数据库和保留策略已被合并,并被 InfluxDB bucket 取代。要使用 InfluxQL 查询 InfluxDB 2.7,指定的 DBRP 组合必须映射到一个 bucket。

自动 DBRP 映射

InfluxDB 2.7 将在以下操作期间自动为你创建 DBRP 映射

更多信息,请参阅 数据库和保留策略映射

虚拟 DBRP 映射

InfluxDB 2.7 为任何没有显式 DBRP 映射关联的 bucket 提供“虚拟”DBRP 映射。虚拟 DBRP 映射使用 bucket 名称来提供一个 DBRP 映射,该映射无需显式定义即可使用。

虚拟 DBRP 映射是只读的。要覆盖虚拟 DBRP 映射,创建一个显式映射

有关如何创建虚拟 DBRP 映射的信息,请参阅 数据库和保留策略映射 – 创建 bucket 时

创建 DBRP 映射

使用 influx CLIInfluxDB API 创建 DBRP 映射。

一个 DBRP 组合只能映射到一个 bucket

每个唯一的 DBRP 组合只能映射到一个 bucket。如果你映射一个已经映射到另一个 bucket 的 DBRP 组合,它将覆盖现有的 DBRP 映射。

使用 influx v1 dbrp create 命令 将未映射的 bucket 映射到数据库和保留策略。包括以下内容

* 必需

  • * orgtoken 用于身份验证。我们建议在 influx CLI 中将你的组织和令牌设置为你的活动 InfluxDB 连接配置,这样你就不必将这些参数添加到每个命令中。要设置你的活动 InfluxDB 配置,请参阅 influx config set
  • * 要映射的数据库名称
  • * 要映射的保留策略名称
  • * 要映射到的 Bucket ID
  • Default flag 用于将提供的保留策略设置为数据库的默认保留策略
influx v1 dbrp create \
  --db example-db \
  --rp example-rp \
  --bucket-id 00oxo0oXx000x0Xo \
  --default

使用 /api/v2/dbrps API 端点 创建新的 DBRP 映射。

POST https://127.0.0.1:8086/api/v2/dbrps

包括以下内容

  • 请求方法: POST
  • 标头
    • Authorization: Token 模式,使用你的 InfluxDB API 令牌
    • Content-type: application/json
  • 请求正文: 具有以下字段的 JSON 对象
    * 必需
    • * bucketID: bucket ID
    • * database: 数据库名称
    • default: 将提供的保留策略设置为数据库的默认保留策略
    • * orgorgID: 组织名称或 组织 ID
    • * retention_policy: 保留策略名称
curl --request POST https://127.0.0.1:8086/api/v2/dbrps \
  --header "Authorization: Token YourAuthToken" \
  --header 'Content-type: application/json' \
  --data '{
        "bucketID": "00oxo0oXx000x0Xo",
        "database": "example-db",
        "default": true,
        "orgID": "00oxo0oXx000x0Xo",
        "retention_policy": "example-rp"
      }'

列出 DBRP 映射

使用 influx CLIInfluxDB API 列出所有 DBRP 映射,并验证你要查询的 bucket 是否已映射到数据库和保留策略。

使用 influx v1 dbrp list 命令 列出 DBRP 映射。

以下示例假定你的组织和 API 令牌由 influx CLI 中活动的 InfluxDB 连接配置 提供。如果不是,请在每个命令中包含你的组织 (--org) 和 API 令牌 (--token)。

查看所有 DBRP 映射
influx v1 dbrp list
按数据库过滤 DBRP 映射
influx v1 dbrp list --db example-db
按 bucket ID 过滤 DBRP 映射
influx v1 dbrp list --bucket-id 00oxo0oXx000x0Xo

使用 /api/v2/dbrps API 端点 列出 DBRP 映射。

GET https://127.0.0.1:8086/api/v2/dbrps

包括以下内容

  • 请求方法: GET
  • 标头
    • Authorization: Token 模式,使用你的 InfluxDB API 令牌
  • 查询参数
    * 必需
    • * orgID: 组织 ID
    • bucketID: bucket ID (列出特定 bucket 的 DBRP 映射)
    • database: 数据库名称 (列出具有特定数据库名称的 DBRP 映射)
    • rp: 保留策略名称 (列出具有特定保留策略名称的 DBRP 映射)
    • id: DBRP 映射 ID (列出特定的 DBRP 映射)
查看所有 DBRP 映射
curl --request GET \
  https://127.0.0.1:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo \
  --header "Authorization: Token YourAuthToken"
按数据库过滤 DBRP 映射
curl --request GET \
  https://127.0.0.1:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo&db=example-db \
  --header "Authorization: Token YourAuthToken"
按 bucket ID 过滤 DBRP 映射
curl --request GET \
  https://cloud2.influxdata.com/api/v2/dbrps?organization_id=00oxo0oXx000x0Xo&bucketID=00oxo0oXx000x0Xo \
  --header "Authorization: Token YourAuthToken"

更新 DBRP 映射

使用 influx CLIInfluxDB API 更新 DBRP 映射。

虚拟 DBRP 映射无法更新。要覆盖虚拟 DBRP 映射,创建一个显式映射

使用 influx v1 dbrp update 命令 更新 DBRP 映射。包括以下内容

* 必需

  • * orgtoken 用于身份验证。我们建议在 influx CLI 中将你的组织和令牌设置为你的活动 InfluxDB 连接配置,这样你就不必将这些参数添加到每个命令中。要设置你的活动 InfluxDB 配置,请参阅 influx config set
  • * 要更新的 DBRP 映射 ID
  • 要更新到的保留策略名称
  • Default flag 用于将保留策略设置为数据库的默认保留策略
更新默认保留策略
influx v1 dbrp update \
  --id 00oxo0X0xx0XXoX0
  --rp example-rp \
  --default

使用 /api/v2/dbrps/{dbrpID} API 端点 更新 DBRP 映射。

PATCH https://127.0.0.1:8086/api/v2/dbrps/{dbrpID}

包括以下内容

* 必需

  • 请求方法: PATCH
  • 标头
    • * Authorization: Token 模式,使用你的 InfluxDB API 令牌
  • 路径参数
    • * id: 要更新的 DBRP 映射 ID
  • 查询参数
  • 请求正文 (JSON)
    • rp: 要更新到的保留策略名称
    • default: 将保留策略设置为数据库的默认保留策略
更新默认保留策略
curl --request PATCH \
  https://127.0.0.1:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
  --header "Authorization: Token YourAuthToken"
  --data '{
      "rp": "example-rp",
      "default": true
    }'

删除 DBRP 映射

使用 influx CLIInfluxDB API 删除 DBRP 映射。

虚拟 DBRP 映射无法删除。

使用 influx v1 dbrp delete 命令 删除 DBRP 映射。包括以下内容

* 必需

  • * orgtoken 用于身份验证。我们建议在 influx CLI 中将你的组织和令牌设置为你的活动 InfluxDB 连接配置,这样你就不必将这些参数添加到每个命令中。要设置你的活动 InfluxDB 配置,请参阅 influx config set
  • * 要删除的 DBRP 映射 ID
influx v1 dbrp delete --id 00oxo0X0xx0XXoX0

使用 /api/v2/dbrps/{dbrpID} API 端点 删除 DBRP 映射。

DELETE https://127.0.0.1:8086/api/v2/dbrps/{dbrpID}

包括以下内容

* 必需

  • 请求方法: PATCH
  • 标头
    • * Authorization: Token 模式,使用你的 InfluxDB API 令牌
  • 路径参数
    • * id: 要更新的 DBRP 映射 ID
  • 查询参数
curl --request DELETE \
  https://127.0.0.1:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
  --header "Authorization: Token YourAuthToken"

此页面是否对您有帮助?

感谢您的反馈!


Flux 的未来

Flux 即将进入维护模式。您可以继续像现在一样使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开发布 Alpha 版

InfluxDB 3 开源版本现已可用于 Alpha 测试,并根据 MIT 或 Apache 2 许可授权。

我们正在发布两个产品作为 Alpha 版本的一部分。

InfluxDB 3 Core 是我们新的开源产品。它是用于时间序列和事件数据的最新数据引擎。InfluxDB 3 Enterprise 是一个商业版本,它建立在 Core 的基础上,增加了历史查询能力、只读副本、高可用性、可扩展性和细粒度的安全性。

有关如何开始使用的更多信息,请查看