Migrate continuous queries to tasks
InfluxDB OSS 2.0 replaces 1.x continuous queries (CQs) with InfluxDB tasks. To migrate continuous queries to InfluxDB 2.0 tasks, do the following:
- Output all InfluxDB 1.x continuous queries
- Convert continuous queries to Flux queries
- Create new InfluxDB tasks
Output all InfluxDB 1.x continuous queries
If using the
influxd upgrade command, by default, all continuous queries are
~/continuous_queries.txt during the upgrade process.
To customize the destination path of the continuous queries file,
--continuous-query-export-path flag with the
influxd upgrade command.
influxd upgrade --continuous-query-export-path /path/to/continuous_queries.txt
To manually output continuous queries:
Use the InfluxDB 1.x
influxinteractive shell to run
show continuous queries:
$ influx Connected to http://localhost:8086 version 1.8.3 InfluxDB shell version: 1.8.3 > show continuous queries
Copy and save the displayed continuous queries.
Convert continuous queries to Flux queries
To migrate InfluxDB 1.x continuous queries to InfluxDB 2.0 tasks, convert the InfluxQL query syntax to Flux.
The majority of continuous queries are simple downsampling queries and can be converted quickly
Example continuous query
CREATE CONTINUOUS QUERY "downsample-daily" ON "my-db" BEGIN SELECT mean("example-field") INTO "average-example-measurement" FROM "example-measurement" GROUP BY time(1h) END
Equivalent Flux query
from(bucket: "my-db/") |> range(start: -1d) |> filter(fn: (r) => r._measurement == "example-measurement") |> filter(fn: (r) => r._field == "example-field") |> aggregateWindow(every: 1h, fn: mean) |> set(key: "_measurement", as: "average-example-measurement") |> to( org: "example-org", bucket: "my-db/downsample-daily" )
Create new InfluxDB tasks
After converting your continuous query to Flux, use the Flux query to create a new task.
Other helpful resources
The following resources are available and may be helpful when converting continuous queries to Flux tasks.
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, the following resources are available:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.