content/shared/influxdb-v2/query-data/influxql/dbrp.md
InfluxQL requires a database and retention policy (DBRP) combination in order to query data. In InfluxDB {{< current-version >}}, databases and retention policies have been combined and replaced by InfluxDB buckets. To query InfluxDB {{< current-version >}} with InfluxQL, the specified DBRP combination must be mapped to a bucket.
InfluxDB {{< current-version >}} will automatically create DBRP mappings for you during the following operations:
/write v1 compatibility endpoint
{{% show-in "cloud,cloud-serverless" %}}- Upgrading from InfluxDB 1.x to InfluxDB Cloud{{% /show-in %}}
{{% show-in "v2" %}}- Upgrading from InfluxDB 1.x to {{< current-version noSpan=true >}}{{% /show-in %}}
{{% show-in "v2" %}}- Creating a bucket (virtual DBRPs){{% /show-in %}}For more information, see Database and retention policy mapping.
{{% show-in "v2" %}}
InfluxDB {{< current-version >}} 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.
{{% /show-in %}}
Use the influx CLI or the
InfluxDB API to create DBRP mappings.
{{% note %}}
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 an unmapped bucket to a database and retention policy.
Include the following:
{{< req type="key" >}}
influx config set.influx v1 dbrp create \
--db example-db \
--rp example-rp \
--bucket-id 00oxo0oXx000x0Xo \
--default
{{% /tab-content %}} {{% tab-content %}}
Use the /api/v2/dbrps API endpoint to create a new DBRP mapping.
{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps" method="POST" api-ref="/influxdb/version/api/#operation/PostDBRP" >}}
Include the following:
POSTToken schema with your InfluxDB API tokenapplication/jsoncurl --request POST http://localhost: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"
}'
{{% /tab-content %}} {{< /tabs-wrapper >}}
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.
{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB API {{% /tabs %}} {{% tab-content %}}
Use the influx v1 dbrp list command to list DBRP mappings.
{{% note %}}
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.
{{% /note %}}
influx v1 dbrp list
influx v1 dbrp list --db example-db
influx v1 dbrp list --bucket-id 00oxo0oXx000x0Xo
{{% /tab-content %}}
{{% tab-content %}}
Use the /api/v2/dbrps API endpoint to list DBRP mappings.
{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps" method="GET" api-ref="/influxdb/version/api/#operation/GetDBRPs" >}}
Include the following:
GETToken schema with your InfluxDB API tokencurl --request GET \
http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo \
--header "Authorization: Token YourAuthToken"
curl --request GET \
http://localhost:8086/api/v2/dbrps?orgID=00oxo0oXx000x0Xo&db=example-db \
--header "Authorization: Token YourAuthToken"
curl --request GET \
https://cloud2.influxdata.com/api/v2/dbrps?organization_id=00oxo0oXx000x0Xo&bucketID=00oxo0oXx000x0Xo \
--header "Authorization: Token YourAuthToken"
{{% /tab-content %}} {{% /tabs-wrapper %}}
Use the influx CLI or the
InfluxDB API to update a DBRP mapping.
{{% show-in "v2" %}}
{{% note %}} Virtual DBRP mappings cannot be updated. To override a virtual DBRP mapping, create an explicit mapping. {{% /note %}}
{{% /show-in %}}
{{< tabs-wrapper >}} {{% tabs %}} influx CLI InfluxDB API {{% /tabs %}} {{% tab-content %}}
Use the influx v1 dbrp update command
to update a DBRP mapping.
Include the following:
{{< req type="key" >}}
influx config set.influx v1 dbrp update \
--id 00oxo0X0xx0XXoX0
--rp example-rp \
--default
{{% /tab-content %}} {{% tab-content %}}
Use the /api/v2/dbrps/{dbrpID} API endpoint to update DBRP mappings.
{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps/{dbrpID}" method="PATCH" api-ref="/influxdb/version/api/#operation/PatchDBRPID" >}}
Include the following:
{{< req type="key" >}}
PATCHToken schema with your InfluxDB API tokencurl --request PATCH \
http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
--header "Authorization: Token YourAuthToken"
--data '{
"rp": "example-rp",
"default": true
}'
{{% /tab-content %}} {{% /tabs-wrapper %}}
Use the influx CLI or the
InfluxDB API to delete a DBRP mapping.
{{% show-in "v2" %}}
{{% note %}} Virtual DBRP mappings cannot be deleted. {{% /note %}}
{{% /show-in %}}
{{< 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" >}}
influx config set.influx v1 dbrp delete --id 00oxo0X0xx0XXoX0
{{% /tab-content %}} {{% tab-content %}}
Use the /api/v2/dbrps/{dbrpID} API endpoint to delete a DBRP mapping.
{{< api-endpoint endpoint="http://localhost:8086/api/v2/dbrps/{dbrpID}" method="DELETE" api-ref="/influxdb/version/api/#operation/DeleteDBRPID" >}}
Include the following:
{{< req type="key" >}}
PATCHToken schema with your InfluxDB API tokencurl --request DELETE \
http://localhost:8086/api/v2/dbrps/00oxo0X0xx0XXoX0?orgID=00oxo0oXx000x0Xo \
--header "Authorization: Token YourAuthToken"
{{% /tab-content %}} {{% /tabs-wrapper %}}