
我想讓一個庫中不同的measurment能夠指定不同的儲存政策。
而不是寫入時使用資料庫的預設保留政策。
Answer:這個特性InfluxDB支援的,寫入時序資料時,在行協定前加上保留政策名,以influx指令行操作為例,insert語句的文法如下。
insert into <rp-name> <line-protocol>
需要注意的是,因為寫入的時序資料記錄對應的保留政策,不是預設保留政策,在查詢相關時序資料記錄時,需要加上保留政策名,select語句的文法格式如下。
select * from <rp-name>.<measurement-name>
例0x00 在資料庫telegraf中,使用非預設保留政策rp-one-year向表devops-idc-sz中寫入時序資料記錄。
(InfluxDB版本:InfluxDB-1.7.8)
> create database telegraf
> use telegraf
Using database telegraf
> create retention policy "rp-one-year" on "telegraf" duration 365d replication 1
> show retention policies on telegraf
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
rp-one-year 8760h0m0s 168h0m0s 1 false
> insert into "rp-one-year" devops-idc-sz,host=server01 cpu=23.1,mem=0.63
> select * from "devops-idc-sz"
>
> select * from "rp-one-year"."devops-idc-sz"
name: devops-idc-sz
time cpu host mem
---- --- ---- ---
1571296987607266011 23.1 server01 0.63
> select * from "telegraf"."rp-one-year"."devops-idc-sz"
name: devops-idc-sz
time cpu host mem
---- --- ---- ---
1571296987607266011 23.1 server01 0.63
>
後記: 歡迎交流讨論:
微信公衆号:influxdb-dev。
InfluxDB技術交流群(QQ):663274123。