InfluxQL offers a full suite of administrative commands.
If you’re looking for
SHOW queries (for example,
SHOW DATABASES or
SHOW RETENTION POLICIES), see Schema Exploration.
The examples in the sections below use InfluxDB’s Command Line Interface (CLI).
You can also execute the commands using the HTTP API; simply send a
GET request to the
/query endpoint and include the command in the URL parameter
See the Querying Data guide for more on using the HTTP API.
Note: When authentication is enabled, only admin users can execute most of the commands listed on this page. See the documentation on authentication and authorization for more information.
Create a database with CREATE DATABASE
CREATE DATABASE query takes the following form:
CREATE DATABASE [IF NOT EXISTS] <database_name> [WITH [DURATION <duration>] [REPLICATION <n>] [NAME <retention-policy-name>]]
IF NOT EXISTSclause does nothing, is deprecated, and will be removed in InfluxDB version 0.12. The
CREATE DATABASEquery will return successfully with no error when a new database is created or if the database already exists.
Create the database
> CREATE DATABASE NOAA_water_database >
Create the database
NOAA_water_database with a new retention policy called
> CREATE DATABASE NOAA_water_database WITH DURATION 3d REPLICATION 3 NAME liquid >
When specifying a retention policy you can include one or more of the attributes
For more on retention policies, see Retention Policy Management
CREATE DATABASE query returns an empty result.
Delete a database with DROP DATABASE
DROP DATABASE query deletes all of the data, measurements, series, continuous queries, and retention policies from the specified database.
The query takes the following form:
DROP DATABASE [IF EXISTS] <database_name>
Drop the database NOAA_water_database:
> DROP DATABASE NOAA_water_database >
Drop the database NOAA_water_database only if it exists:
> DROP DATABASE IF EXISTS NOAA_water_database >
DROP DATABASE query returns an empty result.
Delete series with DROP SERIES
DROP SERIES query deletes all points from series in a database.
The query takes the following form, where you must specify either the
FROM clause or the
DROP SERIES FROM <measurement_name[,measurement_name]> WHERE <tag_key>='<tag_value>'
Delete all series from a single measurement:
> DROP SERIES FROM h2o_feet
Delete series that have a specific tag set from a single measurement:
> DROP SERIES FROM h2o_feet WHERE location = 'santa_monica'
Delete all points in the series that have a specific tag set from all measurements in the database:
> DROP SERIES WHERE location = 'santa_monica'
DROP SERIES query returns an empty result.
DROP SERIES does not support time intervals in the
See GitHub Issue #1647 for more information).
Delete measurements with DROP MEASUREMENT
DROP MEASUREMENT query deletes all data and series from the specified measurement and, unlike
DROP SERIES, it also deletes the measurement from the index.
The query takes the following form:
DROP MEASUREMENT <measurement_name>
Delete the measurement
> DROP MEASUREMENT h2o_feet
DROP MEASUREMENTdrops all data and series in the measurement. It does not drop the associated continuous queries.
DROP MEASUREMENT query returns an empty result.
Currently, InfluxDB does not support regular expressions with
See GitHub Issue #4275 for more information.
Retention Policy Management
The following sections cover how to create, alter, and delete retention policies.
Note that when you create a database, InfluxDB automatically creates a retention policy named
default which has infinite retention.
You may disable that auto-creation in the configuration file.
Create retention policies with CREATE RETENTION POLICY
CREATE RETENTION POLICY query takes the following form, where
DEFAULT is optional:
CREATE RETENTION POLICY <retention_policy_name> ON <database_name> DURATION <duration> REPLICATION <n> [DEFAULT]
DURATIONdetermines how long InfluxDB keeps the data - the options for specifying the duration of the retention policy are listed below. Note that the minimum retention period is one hour.
DURATIONattribute supports only single units. For example, you cannot express the duration
120h 30m. See GitHub Issue #3634 for more information.
REPLICATIONdetermines how many independent copies of each point are stored in the cluster, where
nis the number of data nodes.
DEFAULTsets the new retention policy as the default retention policy for the database.
Create a retention policy called
one_day_only for the database
NOAA_water_database with a one day duration and a replication factor of one:
> CREATE RETENTION POLICY one_day_only ON NOAA_water_database DURATION 1d REPLICATION 1 >
Create the same retention policy as the one in the example above, but set it as the default retention policy for the database.
> CREATE RETENTION POLICY one_day_only ON NOAA_water_database DURATION 1d REPLICATION 1 DEFAULT >
CREATE RETENTION POLICY query returns an empty response.
Note: You can also specify a new retention policy in the
CREATE DATABASEquery. See Create a database with CREATE DATABASE.
Modify retention policies with ALTER RETENTION POLICY
ALTER RETENTION POLICY query takes the following form, where you must declare at least one of the retention policy attributes
ALTER RETENTION POLICY <retention_policy_name> ON <database_name> DURATION <duration> REPLICATION <n> [DEFAULT]
First, create the retention policy
what_is_time with a
DURATION of two days:
> CREATE RETENTION POLICY what_is_time ON NOAA_water_database DURATION 2d REPLICATION 1 >
what_is_time to have a three week
DURATION and make it the
DEFAULT retention policy for
> ALTER RETENTION POLICY what_is_time ON NOAA_water_database DURATION 3w DEFAULT >
In the last example,
what_is_time retains its original replication factor of 1.
ALTER RETENTION POLICY query returns an empty result.
Delete retention policies with DROP RETENTION POLICY
Delete all measurements and data in a specific retention policy with:
DROP RETENTION POLICY <retention_policy_name> ON <database_name>
Delete the retention policy
what_is_time in the
> DROP RETENTION POLICY what_is_time ON NOAA_water_database >
DROP RETENTION POLICY query returns an empty result.
Note: If you attempt
DROPa retention policy that is the default retention policy for the database InfluxDB does not delete the policy and returns the error:
ERR: retention policy is default.
CREATEa new default policy or
ALTERan already existing policy to be the default before deleting the retention policy.