Manage DBRP mappings

InfluxQL requires a database and retention policy (DBRP) combination in order to query data. In InfluxDB 2.7, databases and retention policies have been combined and replaced by InfluxDB buckets. To query InfluxDB 2.7 with InfluxQL, the specified DBRP combination must be mapped to a bucket.

Automatic DBRP mapping

InfluxDB 2.7 will automatically create DBRP mappings for you during the following operations:

For more information, see Database and retention policy mapping.

Virtual DBRP mappings

InfluxDB 2.7 provides “virtual” DBRP mappings for any bucket that does not have an explicit DBRP mapping associated with it. Virtual DBRP mappings use the bucket name to provide a DBRP mapping that can be used without having to explicitly define a mapping.

Virtual DBRP mappings are read-only. To override a virtual DBRP mapping, create an explicit mapping.

For information about how virtual DBRP mappings are created, see Database and retention policy mapping – When creating a bucket.

Create DBRP mappings

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

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.

influx CLI InfluxDB API

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

* Required

  • * org and token to authenticate. We recommend setting your organization and 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.
  • * database name to map
  • * retention policy name to map
  • * Bucket ID to map to
  • Default flag to set the provided retention policy as the default retention policy for the database
  1. influx v1 dbrp create \
  2. --db example-db \
  3. --rp example-rp \
  4. --bucket-id 00oxo0oXx000x0Xo \
  5. --default

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

  1. POST http://localhost:8086/api/v2/dbrps

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:
    * Required
    • * bucketID: bucket ID
    • * database: database name
    • default: set the provided retention policy as the default retention policy for the database
    • * org or orgID: organization name or organization ID
    • * retention_policy: retention policy name
  1. curl --request POST http://localhost:8086/api/v2/dbrps \
  2. --header "Authorization: Token YourAuthToken" \
  3. --header 'Content-type: application/json' \
  4. --data '{
  5. "bucketID": "00oxo0oXx000x0Xo",
  6. "database": "example-db",
  7. "default": true,
  8. "orgID": "00oxo0oXx000x0Xo",
  9. "retention_policy": "example-rp"
  10. }'

List DBRP mappings

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

influx CLI InfluxDB API

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

The examples below assume that your organization and API token are provided by the active InfluxDB connection configuration in the influx CLI. If not, include your organization (--org) and API token (--token) with each command.

View all DBRP mappings
  1. influx v1 dbrp list
Filter DBRP mappings by database
  1. influx v1 dbrp list --db example-db
Filter DBRP mappings by bucket ID
  1. influx v1 dbrp list --bucket-id 00oxo0oXx000x0Xo

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

  1. GET http://localhost:8086/api/v2/dbrps

Include the following:

  • Request method: GET
  • Headers:
    • Authorization: Token schema with your InfluxDB API token
  • Query parameters:
    * Required
    • * 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)
View all DBRP mappings
  1. curl --request GET \
  2. http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo \
  3. --header "Authorization: Token YourAuthToken"
Filter DBRP mappings by database
  1. curl --request GET \
  2. http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo&db=example-db \
  3. --header "Authorization: Token YourAuthToken"
Filter DBRP mappings by bucket ID
  1. curl --request GET \
  2. https://cloud2.influxdata.com/api/v2/dbrps?organization_id=00oxo0oXx000x0Xo&bucketID=00oxo0oXx000x0Xo \
  3. --header "Authorization: Token YourAuthToken"

Update a DBRP mapping

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

Virtual DBRP mappings cannot be updated. To override a virtual DBRP mapping, create an explicit mapping.

influx CLI InfluxDB API

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

* Required

  • * org and token to authenticate. We recommend setting your organization and 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.
  • * 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
  1. influx v1 dbrp update \
  2. --id 00oxo0X0xx0XXoX0
  3. --rp example-rp \
  4. --default

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

  1. PATCH http://localhost:8086/api/v2/dbrps/{dbrpID}

Include the following:

* Required

  • Request method: PATCH
  • Headers:
    • * Authorization: Token schema with your InfluxDB API token
  • Path parameters:
    • * 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
  1. curl --request PATCH \
  2. http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
  3. --header "Authorization: Token YourAuthToken"
  4. --data '{
  5. "rp": "example-rp",
  6. "default": true
  7. }'

Delete a DBRP mapping

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

Virtual DBRP mappings cannot be deleted.

influx CLI InfluxDB API

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

* Required

  • * org and token to authenticate. We recommend setting your organization and 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.
  • * DBRP mapping ID to delete
  1. influx v1 dbrp delete --id 00oxo0X0xx0XXoX0

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

  1. DELETE http://localhost:8086/api/v2/dbrps/{dbrpID}

Include the following:

* Required

  • Request method: PATCH
  • Headers:
    • * Authorization: Token schema with your InfluxDB API token
  • Path parameters:
    • * id: DBRP mapping ID to update
  • Query parameters:
  1. curl --request DELETE \
  2. http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
  3. --header "Authorization: Token YourAuthToken"

influxql dbrp