16 KiB
title | description | menu | weight | list_code_example | related | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a table | Use the Admin UI, the [`influxctl table create` command](/influxdb3/cloud-dedicated/reference/cli/influxctl/table/create/), or the [Management HTTP API](/influxdb3/cloud-dedicated/api/management/) for {{< product-name >}} to create a new table in a specified database your InfluxDB cluster. Create a table with the same partitioning as the database or with a custom partition template. |
|
201 | <!--pytest.mark.skip--> ##### CLI ```bash influxctl table create <DATABASE_NAME> <TABLE_NAME> ``` <!--pytest.mark.skip--> ##### API ```bash curl \ --location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases/DATABASE_NAME/tables/" \ --header "Authorization: Bearer MANAGEMENT_TOKEN" \ --json '{ "name": "TABLE_NAME" }' ``` |
|
Use the Admin UI or the influxctl table create
command
to create a table in a specified database in your
{{< product-name omit=" Clustered" >}} cluster.
With {{< product-name >}}, tables and measurements are synonymous. Typically, tables are created automatically on write using the measurement name specified in line protocol written to InfluxDB. However, to apply a custom partition template to a table, you must manually create the table with custom partitioning before you write any data to it.
Partitioning defaults to %Y-%m-%d
(daily).
When a partition template is applied to a database, it becomes the default template
for all tables in that database, but can be overridden when creating a
table.
- Create a table
- Create a table with custom partitioning
- Partition template requirements and guidelines
Create a table
{{< tabs-wrapper >}} {{% tabs %}} Admin UI influxctl Management API {{% /tabs %}} {{% tab-content %}}
The InfluxDB Cloud Dedicated administrative UI includes a portal for creating and managing tables.
-
To access the {{< product-name >}} Admin UI, visit the following URL in your browser:
https://console.influxdata.com
-
Use the credentials provided by InfluxData to log into the Admin UI. If you don't have login credentials, contact InfluxData support.
-
In the cluster list, find and click the cluster you want to create a database in. You can sort on column headers or use the Search field to find a specific cluster.
-
In the database list, find and click the database you want to create a table in. You can sort on column headers or use the Search field to find a specific database.
-
Click the New Table button above the table list. The Create table dialog displays.
{{< img-hd src="/img/influxdb3/cloud-dedicated-admin-ui-create-table-default.png" alt="Create table dialog" />}}
-
In the Create table dialog, provide a Table name.
-
Leave Use custom partitioning set to Off. By default, the table inherits the database's partition template. If no custom partition template is applied to the database, the table inherits the default partitioning of
%Y-%m-%d
(daily). -
Click the Create Table button.
{{% /tab-content %}} {{% tab-content %}}
- If you haven't already, download and install the
influxctl
CLI. - Run the
influxctl table create
command:
{{% code-placeholders "(DATABASE|TABLE)_NAME" %}}
# Create a table with the same partitioning as the database
influxctl table create \
DATABASE_NAME \
TABLE_NAME
{{% /code-placeholders %}}
Replace:
- {{% code-placeholder-key %}}
DATABASE_NAME
{{% /code-placeholder-key %}}: the database to create the table in - {{% code-placeholder-key %}}
TABLE_NAME
{{% /code-placeholder-key %}}: the name for your new table
{{% /tab-content %}} {{% tab-content %}}
This example uses cURL to send a Management HTTP API request, but you can use any HTTP client.
- If you haven't already, follow the instructions to install cURL for your system.
- In your terminal, use cURL to send a request to the following {{% product-name %}} endpoint:
{{% api-endpoint method="POST" endpoint="https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases/DATABASE_NAME/tables" api-ref="/influxdb3/cloud-dedicated/api/management/#operation/CreateClusterDatabaseTable" %}}
{{% code-placeholders "ACCOUNT_ID|CLUSTER_ID|DATABASE_NAME|TABLE_NAME|MANAGEMENT_TOKEN" %}}
# Create a table with the same partitioning as the database
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases/DATABASE_NAME/tables" \
--request POST \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--json '{
"name": "TABLE_NAME"
}'
{{% /code-placeholders %}}
Replace the following:
- {{% code-placeholder-key %}}
ACCOUNT_ID
{{% /code-placeholder-key %}}: the account ID for the cluster (list details via the Admin UI or CLI) - {{% code-placeholder-key %}}
CLUSTER_ID
{{% /code-placeholder-key %}}: the cluster ID (list details via the Admin UI or CLI). - {{% code-placeholder-key %}}
MANAGEMENT_TOKEN
{{% /code-placeholder-key %}}: a valid management token for your {{% product-name %}} cluster - {{% code-placeholder-key %}}
DATABASE_NAME
{{% /code-placeholder-key %}}: the name of the database to create the table in - {{% code-placeholder-key %}}
TABLE_NAME
{{% /code-placeholder-key %}}: the name for your new table
{{% /tab-content %}} {{< /tabs-wrapper >}}
Create a table with custom partitioning
{{< product-name >}} lets you define a custom partitioning strategy for each database and table. A partition is a logical grouping of data stored in Apache Parquet By default, data is partitioned by day, but, depending on your schema and workload, customizing the partitioning strategy can improve query performance.
To use custom partitioning, you define a partition template. If a table doesn't have a custom partition template, it inherits the database's template.
{{< tabs-wrapper >}} {{% tabs %}} Admin UI influxctl Management API {{% /tabs %}} {{% tab-content %}}
-
To access the {{< product-name >}} Admin UI, visit the following URL in your browser:
https://console.influxdata.com
-
Use the credentials provided by InfluxData to log into the Admin UI. If you don't have login credentials, contact InfluxData support.
-
In the cluster list, find and click the cluster you want to create a database in. You can sort on column headers or use the Search field to find a specific cluster.
-
In the database list, find and click the database you want to create a table in. You can sort on column headers or use the Search field to find a specific database.
-
Click the New Table button above the table list. The Create table dialog displays.
{{< img-hd src="/img/influxdb3/cloud-dedicated-admin-ui-create-table-default.png" alt="Create table dialog" />}}
-
In the Create table dialog, provide a Table name.
-
Toggle Use custom partitioning to On. The Custom partition template section displays.
{{< img-hd src="/img/influxdb3/cloud-dedicated-admin-ui-create-table-custom-partitioning.png" alt="Create table dialog with custom partitioning" />}}
-
Provide the following:
- Custom partition template time format: The time part for partitioning data (yearly, monthly, or daily).
- Optional: Custom partition template tag parts: The tag parts for partitioning data.
- Optional: Custom partition template tag bucket parts: The tag bucket parts for partitioning data.
-
Optional: To add more parts to the partition template, click the Add Tag button. For more information, see Partition template requirements and guidelines.
-
Click the Create Table button to create the table. The new table displays in the list of tables for the cluster. {{% /tab-content %}} {{% tab-content %}}
-
If you haven't already, download and install the
influxctl
CLI. -
Use the following
influxctl table create
command flags to specify the partition template parts:-
--template-timeformat
: A Rust strftime date and time string that specifies the time part in the partition template and determines the time interval to partition by. Use one of the following:%Y-%m-%d
(daily)%Y-%m
(monthly)%Y
(annually)
-
--template-tag
: An [InfluxDB tag] to use in the partition template. -
--template-tag-bucket
: An InfluxDB tag and number of "buckets" to group tag values into. Provide the tag key and the number of buckets to bucket tag values into separated by a comma:tagKey,N
.
-
{{% code-placeholders "DATABASE_NAME|30d|(TAG_KEY(_\d)?)|100|300" %}}
# Create a table with custom partitioning
influxctl table create \
--template-tag tag1 \
--template-tag tag2 \
--template-tag-bucket tag3,100 \
--template-tag-bucket tag4,300 \
--template-timeformat '%Y-%m-%d' \
DATABASE_NAME \
TABLE_NAME
{{% /code-placeholders %}}
Replace the following:
- {{% code-placeholder-key %}}
TAG_KEY_1
,TAG_KEY_2
{{% /code-placeholder-key %}}: tag keys to partition by - {{% code-placeholder-key %}}
TAG_KEY_3
,TAG_KEY_4
{{% /code-placeholder-key %}}: tag keys for bucketed partitioning - {{% code-placeholder-key %}}
100
,300
{{% /code-placeholder-key %}}: number of buckets to group tag values into - {{% code-placeholder-key %}}
'%Y-%m-%d'
{{% /code-placeholder-key %}}: Rust strftime date and time string that specifies the time part in the partition template - {{% code-placeholder-key %}}
DATABASE_NAME
{{% /code-placeholder-key %}}: the name of the database to create the table in - {{% code-placeholder-key %}}
TABLE_NAME
{{% /code-placeholder-key %}}: the name you want for the new table {{% /tab-content %}} {{% tab-content %}}
This example uses cURL to send a Management HTTP API request, but you can use any HTTP client.
- If you haven't already, follow the instructions to install cURL for your system.
- In your terminal, use cURL to send a request to the following {{% product-name %}} endpoint:
{{% api-endpoint method="POST" endpoint="https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases/DATABASE_NAME/tables" api-ref="/influxdb3/cloud-dedicated/api/management/#operation/CreateClusterDatabaseTable" %}}
In the request body, include the partitionTemplate
property and specify the partition template parts as an array of objects--for example:
{{% code-placeholders "ACCOUNT_ID|CLUSTER_ID|DATABASE_NAME|MANAGEMENT_TOKEN|TABLE_NAME|(TAG_KEY(_\d)?)|100|300|%Y-%m-%d" %}}
# Create a table with custom partitioning
curl \
--location "https://console.influxdata.com/api/v0/accounts/ACCOUNT_ID/clusters/CLUSTER_ID/databases/DATABASE_NAME/tables" \
--request POST \
--header "Authorization: Bearer MANAGEMENT_TOKEN" \
--json '{
"name": "TABLE_NAME",
"partitionTemplate": [
{ "type": "tag", "value": "TAG_KEY_1" },
{ "type": "tag", "value": "TAG_KEY_2" },
{ "type": "bucket", "value": { "tagName": "TAG_KEY_3", "numberOfBuckets": 100 } },
{ "type": "bucket", "value": { "tagName": "TAG_KEY_4", "numberOfBuckets": 300 } },
{ "type": "time", "value": "%Y-%m-%d" }
]
}'
{{% /code-placeholders %}}
Replace the following:
- {{% code-placeholder-key %}}
ACCOUNT_ID
{{% /code-placeholder-key %}}: the account ID for the cluster (list details via the Admin UI or CLI) - {{% code-placeholder-key %}}
CLUSTER_ID
{{% /code-placeholder-key %}}: the cluster ID (list details via the Admin UI or CLI). - {{% code-placeholder-key %}}
MANAGEMENT_TOKEN
{{% /code-placeholder-key %}}: a valid management token for your {{% product-name %}} cluster - {{% code-placeholder-key %}}
DATABASE_NAME
{{% /code-placeholder-key %}}: the name of the database to create the table in - {{% code-placeholder-key %}}
TABLE_NAME
{{% /code-placeholder-key %}}: the name you want for the new table - {{% code-placeholder-key %}}
TAG_KEY_1
,TAG_KEY_2
{{% /code-placeholder-key %}}: tag keys to partition by - {{% code-placeholder-key %}}
TAG_KEY_3
,TAG_KEY_4
{{% /code-placeholder-key %}}: tag keys for bucketed partitioning - {{% code-placeholder-key %}}
100
,300
{{% /code-placeholder-key %}}: number of buckets to group tag values into - {{% code-placeholder-key %}}
'%Y-%m-%d'
{{% /code-placeholder-key %}}: Rust strftime date and time string that specifies the time part in the partition template {{% /tab-content %}} {{< /tabs-wrapper >}}
Partition template requirements and guidelines
Always specify 1 time part in your template. A template has a maximum of 8 parts: 1 time part and up to 7 total tag and tag bucket parts.
For more information about partition template requirements and restrictions, see Partition templates.
[!Warning]
Partition templates can only be applied on create
You can only apply a partition template when creating a table. You can't update a partition template on an existing table.