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:

  1. Output all InfluxDB 1.x continuous queries
  2. Convert continuous queries to Flux queries
  3. Create new InfluxDB tasks

Output all InfluxDB 1.x continuous queries

If using the influxd upgrade command, by default, all continuous queries are output to ~/continuous_queries.txt during the upgrade process. To customize the destination path of the continuous queries file, use the --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:

  1. Use the InfluxDB 1.x influx interactive 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
  2. 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 using the aggregateWindow() function. For example:

Example continuous query
CREATE CONTINUOUS QUERY "downsample-daily" ON "my-db"
  SELECT mean("example-field")
  INTO "average-example-measurement"
  FROM "example-measurement"
  GROUP BY time(1h)
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.


New! Cloud or OSS?

InfluxDB OSS 2.0 now generally available!

InfluxDB OSS 2.0 is now generally available and ready for production use. See the InfluxDB OSS 2.0 release notes.

For information about upgrading to InfluxDB OSS 2.0, see: