管理 DBRP 映射
InfluxQL 需要数据库和保留策略 (DBRP) 组合才能查询数据。在 InfluxDB 2.7 中,数据库和保留策略已被合并,并被 InfluxDB bucket 取代。要使用 InfluxQL 查询 InfluxDB 2.7,指定的 DBRP 组合必须映射到一个 bucket。
自动 DBRP 映射
InfluxDB 2.7 将在以下操作期间自动为你创建 DBRP 映射
- 写入
/write
v1 兼容性端点 - 从 InfluxDB 1.x 升级到 2.7
- 创建 bucket (虚拟 DBRP)
更多信息,请参阅 数据库和保留策略映射。
虚拟 DBRP 映射
InfluxDB 2.7 为任何没有显式 DBRP 映射关联的 bucket 提供“虚拟”DBRP 映射。虚拟 DBRP 映射使用 bucket 名称来提供一个 DBRP 映射,该映射无需显式定义即可使用。
虚拟 DBRP 映射是只读的。要覆盖虚拟 DBRP 映射,创建一个显式映射。
有关如何创建虚拟 DBRP 映射的信息,请参阅 数据库和保留策略映射 – 创建 bucket 时。
创建 DBRP 映射
使用 influx
CLI 或 InfluxDB API 创建 DBRP 映射。
一个 DBRP 组合只能映射到一个 bucket
每个唯一的 DBRP 组合只能映射到一个 bucket。如果你映射一个已经映射到另一个 bucket 的 DBRP 组合,它将覆盖现有的 DBRP 映射。
使用 influx v1 dbrp create
命令 将未映射的 bucket 映射到数据库和保留策略。包括以下内容
* 必需
- * org 和 token 用于身份验证。我们建议在 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
- Authorization:
- 请求正文: 具有以下字段的 JSON 对象
* 必需
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
CLI 或 InfluxDB 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 令牌
- Authorization:
- 查询参数
* 必需
查看所有 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
CLI 或 InfluxDB API 更新 DBRP 映射。
虚拟 DBRP 映射无法更新。要覆盖虚拟 DBRP 映射,创建一个显式映射。
使用 influx v1 dbrp update
命令 更新 DBRP 映射。包括以下内容
* 必需
- * org 和 token 用于身份验证。我们建议在 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 令牌
- * Authorization:
- 路径参数
- * id: 要更新的 DBRP 映射 ID
- 查询参数
- * orgID: 组织 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
CLI 或 InfluxDB API 删除 DBRP 映射。
虚拟 DBRP 映射无法删除。
使用 influx v1 dbrp delete
命令 删除 DBRP 映射。包括以下内容
* 必需
- * org 和 token 用于身份验证。我们建议在 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 令牌
- * Authorization:
- 路径参数
- * id: 要更新的 DBRP 映射 ID
- 查询参数
- * orgID: 组织 ID
curl --request DELETE \
https://127.0.0.1:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
--header "Authorization: Token YourAuthToken"
此页面是否对您有帮助?
感谢您的反馈!
支持和反馈
感谢您成为我们社区的一份子!我们欢迎并鼓励您提供关于 InfluxDB 和本文档的反馈和错误报告。如需获得支持,请使用以下资源
拥有年度合同或支持合同的客户 可以 联系 InfluxData 支持。