@@ -10,161 +10,9 @@ weight: 202
10
10
related :
11
11
- /influxdb/cloud-dedicated/reference/cli/influxctl/database/create/
12
12
- /influxdb/cloud-dedicated/reference/cli/influxctl/table/create/
13
+ source : /shared/v3-distributed-admin-custom-partitions/define-custom-partitions.md
13
14
---
14
15
15
- Use the [ ` influxctl ` CLI] ( /influxdb/cloud-dedicated/reference/cli/influxctl/ )
16
- to define custom partition strategies when creating a database or table.
17
- By default, {{< product-name >}} partitions data by day.
18
-
19
- The partitioning strategy of a database or table is determined by a
20
- [ partition template] ( /influxdb/cloud-dedicated/admin/custom-partitions/#partition-templates )
21
- which defines the naming pattern for [ partition keys] ( /influxdb/cloud-dedicated/admin/custom-partitions/#partition-keys ) .
22
- Partition keys uniquely identify each partition.
23
- When a partition template is applied to a database, it becomes the default template
24
- for all tables in that database, but can be overridden when creating a
25
- table.
26
-
27
- - [ Create a database with a custom partition template] ( #create-a-database-with-a-custom-partition-template )
28
- - [ Create a table with a custom partition template] ( #create-a-table-with-a-custom-partition-template )
29
- - [ Example partition templates] ( #example-partition-templates )
30
-
31
- {{% warn %}}
32
-
33
- #### Partition templates can only be applied on create
34
-
35
- You can only apply a partition template when creating a database or table.
36
- You can't update a partition template on an existing resource.
37
- {{% /warn %}}
38
-
39
- Use the following command flags to identify
40
- [ partition template parts] ( /influxdb/cloud-dedicated/admin/custom-partitions/partition-templates/#tag-part-templates ) :
41
-
42
- - ` --template-tag ` : An [ InfluxDB tag] ( /influxdb/cloud-dedicated/reference/glossary/#tag )
43
- to use in the partition template.
44
- - ` --template-tag-bucket ` : An [ InfluxDB tag] ( /influxdb/cloud-dedicated/reference/glossary/#tag )
45
- and number of "buckets" to group tag values into.
46
- Provide the tag key and the number of buckets to bucket tag values into
47
- separated by a comma: ` tagKey,N ` .
48
- - ` --template-timeformat ` : A [ Rust strftime date and time] ( /influxdb/cloud-dedicated/admin/custom-partitions/partition-templates/#time-part-templates )
49
- string that specifies the time format in the partition template and determines
50
- the time interval to partition by.
51
-
52
- {{% note %}}
53
- A partition template can include up to 7 total tag and tag bucket parts
54
- and only 1 time part.
55
- {{% /note %}}
56
-
57
- _ View [ partition template part restrictions] ( /influxdb/cloud-dedicated/admin/custom-partitions/partition-templates/#restrictions ) ._
58
-
59
- {{% note %}}
60
- #### Always provide a time format when using custom partitioning
61
-
62
- When defining a custom partition template for your database or table using any
63
- of the ` influxctl ` ` --template-* ` flags, always include the ` --template-timeformat `
64
- flag with a time format to use in your partition template.
65
- Otherwise, InfluxDB omits time from the partition template and won't compact partitions.
66
- {{% /note %}}
67
-
68
- ## Create a database with a custom partition template
69
-
70
- The following example creates a new ` example-db ` database and applies a partition
71
- template that partitions by distinct values of two tags (` room ` and ` sensor-type ` ),
72
- bucketed values of the ` customerID ` tag, and by day using the time format ` %Y-%m-%d ` :
73
-
74
- <!-- Skip database create and delete tests: namespaces aren't reusable-->
75
- <!-- pytest.mark.skip-->
76
-
77
- ``` sh
78
- influxctl database create \
79
- --template-tag room \
80
- --template-tag sensor-type \
81
- --template-tag-bucket customerID,500 \
82
- --template-timeformat ' %Y-%m-%d' \
83
- example-db
84
- ```
85
-
86
- ## Create a table with a custom partition template
87
-
88
- The following example creates a new ` example-table ` table in the specified
89
- database and applies a partition template that partitions by distinct values of
90
- two tags (` room ` and ` sensor-type ` ), bucketed values of the ` customerID ` tag,
91
- and by month using the time format ` %Y-%m ` :
92
-
93
- <!-- Skip database create and delete tests: namespaces aren't reusable-->
94
- <!-- pytest.mark.skip-->
95
-
96
- {{% code-placeholders "DATABASE_NAME" %}}
97
-
98
- ``` sh
99
- influxctl table create \
100
- --template-tag room \
101
- --template-tag sensor-type \
102
- --template-tag-bucket customerID,500 \
103
- --template-timeformat ' %Y-%m' \
104
- DATABASE_NAME \
105
- example-table
106
- ```
107
-
108
- {{% /code-placeholders %}}
109
-
110
- Replace the following in your command:
111
-
112
- - {{% code-placeholder-key %}}` DATABASE_NAME ` {{% /code-placeholder-key %}}: your {{% product-name %}} [ database] ( /influxdb/cloud-dedicated/admin/databases/ )
113
-
114
- <!-- actual test
115
-
116
- ```sh
117
-
118
- # Test the preceding command outside of the code block.
119
- # influxctl authentication requires TTY interaction--
120
- # output the auth URL to a file that the host can open.
121
-
122
- TABLE_NAME=table_TEST_RUN
123
- script -c "influxctl table create \
124
- --template-tag room \
125
- --template-tag sensor-type \
126
- --template-tag-bucket customerID,500 \
127
- --template-timeformat '%Y-%m' \
128
- DATABASE_NAME \
129
- $TABLE_NAME" \
130
- /dev/null > /shared/urls.txt
131
-
132
- script -c "influxctl query \
133
- --database DATABASE_NAME \
134
- --token DATABASE_TOKEN \
135
- 'SHOW TABLES'" > /shared/temp_tables.txt
136
- grep -q $TABLE_NAME /shared/temp_tables.txt
137
- rm /shared/temp_tables.txt
138
- ```
139
-
16
+ <!--
17
+ The content of this page is at /content/shared/v3-distributed-admin-custom-partitions/_define-custom-partitions.md
140
18
-->
141
-
142
- ## Example partition templates
143
-
144
- Given the following [ line protocol] ( /influxdb/cloud-dedicated/reference/syntax/line-protocol/ )
145
- with a ` 2024-01-01T00:00:00Z ` timestamp:
146
-
147
- ``` text
148
- prod,line=A,station=weld1 temp=81.9,qty=36i 1704067200000000000
149
- ```
150
-
151
- ##### Partitioning by distinct tag values
152
-
153
- | Description | Tag parts | Time part | Resulting partition key |
154
- | :---------------------- | :---------------- | :--------- | :----------------------- |
155
- | By day (default) | | ` %Y-%m-%d ` | 2024-01-01 |
156
- | By month | | ` %Y-%m ` | 2024-01 |
157
- | By year | | ` %Y ` | 2024 |
158
- | Single tag, by day | ` line ` | ` %Y-%m-%d ` | A \| 2024-01-01 |
159
- | Single tag, by month | ` line ` | ` %Y-%m ` | A \| 2024-01 |
160
- | Single tag, by year | ` line ` | ` %Y ` | A \| 2024 |
161
- | Multiple tags, by day | ` line ` , ` station ` | ` %Y-%m-%d ` | A \| weld1 \| 2024-01-01 |
162
- | Multiple tags, by month | ` line ` , ` station ` | ` %Y-%m ` | A \| weld1 \| 2024-01 |
163
- | Multiple tags, by year | ` line ` , ` station ` | ` %Y ` | A \| weld1 \| 2024 |
164
-
165
- ##### Partition by tag buckets
166
-
167
- | Description | Tag part | Tag bucket part | Time part | Resulting partition key |
168
- | :---------------------------------- | :------- | :-------------- | :--------- | :---------------------- |
169
- | Distinct tag, tag buckets, by day | ` line ` | ` station,100 ` | ` %Y-%m-%d ` | A \| 3 \| 2024-01-01 |
170
- | Distinct tag, tag buckets, by month | ` line ` | ` station,500 ` | ` %Y-%m ` | A \| 303 \| 2024-01 |
0 commit comments