docs-v2/content/influxdb/cloud-serverless/query-data/influxql/dbrp.md

12 KiB

title description menu weight
Map databases and retention policies to buckets To query an an InfluxDB Cloud Serverless bucket with InfluxQL, first map each database and retention policy (DBRP) combination to a bucket.
influxdb_cloud_serverless
name parent
DBRP mappings Query with InfluxQL
101

InfluxQL requires a database and retention policy (DBRP) combination in order to query data. In {{< product-name >}}, databases and retention policies are combined and replaced by InfluxDB buckets. To query an {{< product-name >}} bucket with InfluxQL, first map each DBRP combination to a bucket.

Automatic DBRP mapping

{{< product-name >}} automatically creates DBRP mappings for you during the following operations:

For more information, see Database and retention policy mapping.

Create DBRP mappings

Use the influx CLI or the InfluxDB API to create DBRP mappings.

{{% note %}}

A DBRP combination can only be mapped to a single bucket

Each unique DBRP combination can only be mapped to a single bucket. If you map a DBRP combination that is already mapped to another bucket, it will overwrite the existing DBRP mapping. {{% /note %}}

{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB API {{% /tabs %}} {{% tab-content %}}

Use the influx v1 dbrp create command to map a database and retention policy to a bucket. Include the following:

{{< req type="key" >}}

  • {{< req "*" >}} API token to authenticate. We recommend setting your token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see influx config set.
  • {{< req "*" >}} database name to map
  • {{< req "*" >}} retention policy name to map
  • {{< req "*" >}} Bucket ID to map to
  • Default flag to set the provided retention policy as the default retention policy for the database

{{% code-placeholders "(DATABASE|RETENTION_POLICY|BUCKET|API)_(NAME|TOKEN|ID)" %}}

influx v1 dbrp create \
  --token API_TOKEN \
  --db DATABASE_NAME \
  --rp RETENTION_POLICY_NAME \
  --bucket-id BUCKET_ID \
  --default

{{% /code-placeholders %}}

{{% /tab-content %}} {{% tab-content %}}

Use the /api/v2/dbrps API endpoint to create a new DBRP mapping.

{{< api-endpoint endpoint="https://{{< influxdb/host >}}/api/v2/dbrps" method="POST" api-ref="/influxdb/cloud-serverless/api/#operation/PostDBRP" >}}

Include the following:

  • Request method: POST
  • Headers:
    • Authorization: Token schema with your InfluxDB API token
    • Content-type: application/json
  • Request body: JSON object with the following fields:
    {{< req type="key" >}}
    • {{< req "*" >}} bucketID: bucket ID
    • {{< req "*" >}} database: database name
    • default: set the provided retention policy as the default retention policy for the database
    • {{< req "*" >}} org or orgID: organization name or organization ID
    • {{< req "*" >}} retention_policy: retention policy name

{{% code-placeholders "(DATABASE|RETENTION_POLICY|BUCKET|API|ORG)_(NAME|TOKEN|ID)" %}}

curl --request POST https://{{< influxdb/host >}}/api/v2/dbrps \
  --header "Authorization: Token API_TOKEN" \
  --header 'Content-type: application/json' \
  --data '{
        "bucketID": "BUCKET_ID",
        "database": "DATABASE_NAME",
        "default": true,
        "orgID": "ORG_ID",
        "retention_policy": "RETENTION_POLICY_NAME"
      }'

{{% /code-placeholders %}}

{{% /tab-content %}} {{< /tabs-wrapper >}}

List DBRP mappings

Use the influx CLI or the InfluxDB HTTP API to list all DBRP mappings and verify the buckets you want to query are mapped to a database and retention policy.

{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB HTTP API {{% /tabs %}} {{% tab-content %}}

Use the influx v1 dbrp list command to list DBRP mappings.

View all DBRP mappings

{{% code-placeholders "(DATABASE|RETENTION_POLICY|BUCKET|API|ORG)_(NAME|TOKEN|ID)" %}}

influx v1 dbrp list --token API_TOKEN
Filter DBRP mappings by database
influx v1 dbrp list \
  --token API_TOKEN \
  --db DATABASE_NAME
Filter DBRP mappings by bucket ID
influx v1 dbrp list \
  --token API_TOKEN \
  --bucket-id BUCKET_ID

{{% /code-placeholders %}}

{{% /tab-content %}} {{% tab-content %}}

Use the /api/v2/dbrps API endpoint to list DBRP mappings.

{{< api-endpoint endpoint="https://{{< influxdb/host >}}/api/v2/dbrps" method="GET" api-ref="/influxdb/cloud-serverless/api/#operation/GetDBRPs" >}}

Include the following:

  • Request method: GET
  • Headers:
    • Authorization: Token schema with your InfluxDB API token
  • Query parameters:
    {{< req type="key" >}}
    • {{< req "*" >}} orgID: organization ID
    • bucketID: bucket ID (to list DBRP mappings for a specific bucket)
    • database: database name (to list DBRP mappings with a specific database name)
    • rp: retention policy name (to list DBRP mappings with a specific retention policy name)
    • id: DBRP mapping ID (to list a specific DBRP mapping)

{{% code-placeholders "(DATABASE|RETENTION_POLICY|BUCKET|API|ORG)_(NAME|TOKEN|ID)" %}}

View all DBRP mappings
curl --request GET \
  https://{{< influxdb/host >}}/api/v2/dbrps \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "orgID=ORG_ID"
Filter DBRP mappings by database
curl --request GET \
  https://{{< influxdb/host >}}/api/v2/dbrps \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "orgID=ORG_ID" \
  --data-urlencode  "db=DATABASE_NAME"
Filter DBRP mappings by bucket ID
curl --request GET \
  https://{{< influxdb/host >}}/api/v2/dbrps \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "orgID=ORG_ID" \
  --data-urlencode  "bucketID=BUCKET_ID"

{{% /code-placeholders %}}

{{% /tab-content %}} {{% /tabs-wrapper %}}

Update a DBRP mapping

Use the influx CLI or the InfluxDB HTTP API to update a DBRP mapping.

{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB HTTP API {{% /tabs %}} {{% tab-content %}}

Use the influx v1 dbrp update command to update a DBRP mapping. Include the following:

{{< req type="key" >}}

  • {{< req "*" >}} API token to authenticate. We recommend setting your token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see influx config set.
  • {{< req "*" >}} DBRP mapping ID to update
  • Retention policy name to update to
  • Default flag to set the retention policy as the default retention policy for the database
Update the default retention policy

{{% code-placeholders "(DBRP|RETENTION_POLICY|API)_(NAME|TOKEN|ID)" %}}

influx v1 dbrp update \
  --token API_TOKEN \
  --id DBRP_ID \
  --rp RETENTION_POLICY_NAME \
  --default

{{% /code-placeholders %}}

{{% /tab-content %}} {{% tab-content %}}

Use the /api/v2/dbrps/{dbrpID} API endpoint to update DBRP mappings.

{{< api-endpoint endpoint="https://{{< influxdb/host >}}/api/v2/dbrps/{dbrpID}" method="PATCH" api-ref="/influxdb/cloud-serverless/api/#operation/PatchDBRPID" >}}

Include the following:

{{< req type="key" >}}

  • Request method: PATCH
  • Headers:
    • {{< req "*" >}} Authorization: Token schema with your InfluxDB API token
  • Path parameters:
    • {{< req "*" >}} id: DBRP mapping ID to update
  • Query parameters:
  • Request body (JSON):
    • rp: retention policy name to update to
    • default: set the retention policy as the default retention policy for the database
Update the default retention policy

{{% code-placeholders "(DBRP|RETENTION_POLICY|API|ORG)_(NAME|TOKEN|ID)" %}}

curl --request PATCH \
  https://{{< influxdb/host >}}/api/v2/dbrps/DBRP_ID \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "orgID=ORG_ID" \
  --data '{
      "rp": "RETENTION_POLICY_NAME",
      "default": true
    }'

{{% /code-placeholders %}} {{% /tab-content %}} {{% /tabs-wrapper %}}

Delete a DBRP mapping

Use the influx CLI or the InfluxDB API to delete a DBRP mapping.

{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB API {{% /tabs %}} {{% tab-content %}}

Use the influx v1 dbrp delete command to delete a DBRP mapping. Include the following:

{{< req type="key" >}}

  • {{< req "*" >}} API token to authenticate. We recommend setting your token to your active InfluxDB connection configuration in the influx CLI, so you don't have to add these parameters to each command. To set up your active InfluxDB configuration, see influx config set.
  • {{< req "*" >}} DBRP mapping ID to delete

{{% code-placeholders "(DBRP|API)_(TOKEN|ID)" %}}

influx v1 dbrp delete \
  --token API_TOKEN \
  --id DBRP_ID

{{% /code-placeholders %}}

{{% /tab-content %}} {{% tab-content %}}

Use the /api/v2/dbrps/{dbrpID} API endpoint to delete a DBRP mapping.

{{< api-endpoint endpoint="https://{{< influxdb/host >}}/api/v2/dbrps/{dbrpID}" method="DELETE" api-ref="/influxdb/cloud-serverless/api/#operation/DeleteDBRPID" >}}

Include the following:

{{< req type="key" >}}

  • Request method: PATCH
  • Headers:
    • {{< req "*" >}} Authorization: Token schema with your InfluxDB API token
  • Path parameters:
    • {{< req "*" >}} id: DBRP mapping ID to update
  • Query parameters:

{{% code-placeholders "(DBRP|API|ORG)_(TOKEN|ID)" %}}

curl --request DELETE \
  https://{{< influxdb/host >}}/api/v2/dbrps/DBRP_ID \
  --header "Authorization: Token API_TOKEN" \
  --data-urlencode "orgID=ORG_ID"

{{% /code-placeholders %}} {{% /tab-content %}} {{% /tabs-wrapper %}}