influx

influx Retention Policy

settings

Example:

Setting           Value
--------          --------
Host              localhost:8086
Username          
Database          ruuvi
RetentionPolicy   
Pretty            false
Format            column
Write Consistency all 
Chunked           true
Chunk Size        0 
# Clear the database context
clear database
clear db

# Clear the retention policy context
clear retention policy
clear rp 

Retention Policy defines How long data is kept(duration), how many copies of this data is stored in the cluster (replication factor), and the time range covered by shard groups (shard group duration). Retention Policies are unique per database.

When a database is created, the default is autogen with an infinite duration, a replication factor of 1, and a shard group duration of 7d (7*24=168h).

shard group has a retention policy and shard group duration(window of time each shard group spans ). Retention policy enforcement drops an entire shard group

CREATE RETENTION POLICY retention_policy_name ON database_name
   DURATION duration REPLICATION n
  [SHARD DURATION sduration] [DEFAULT]

duration must be greater than 1h
sduration must be greater than 1h, defaults to 1h if duration < 2d; 7d if duration > 6m and 1d otherwise.

 SHOW RETENTION POLICIES on ruuvi
name    duration shardGroupDuration replican default
----    -------- ------------------ -------- -------
autogen 0s       168h0m0s           1        true


 SHOW SHARDS

name: ruuvi
id  database retention_policy shard_group start_time           end_time             expiry_time          owners
--  -------- ---------------- ----------- ----------           --------             -----------          ------
2   ruuvi    autogen          2           2018-01-29T00:00:00Z 2018-02-05T00:00:00Z 2018-02-05T00:00:00Z 
5   ruuvi    autogen          5           2018-03-19           2018-03-26           2018-03-26           
10  ruuvi    autogen          10          2018-03-26           2018-04-02           2018-04-02           
17  ruuvi    autogen          17          2018-04-16           2018-04-23           2018-04-23           
31  ruuvi    autogen          31          2018-04-23           2018-04-30           2018-04-30           
39  ruuvi    autogen          39          2018-04-30           2018-05-07           2018-05-07           
47  ruuvi    autogen          47          2018-05-07           2018-05-14           2018-05-14           
55  ruuvi    autogen          55          2018-05-14           2018-05-21           2018-05-21           
63  ruuvi    autogen          63          2018-05-21           2018-05-28           2018-05-28           
71  ruuvi    autogen          71          2018-05-28           2018-06-04           2018-06-04           
79  ruuvi    autogen          79          2018-06-04           2018-06-11           2018-06-11           
87  ruuvi    autogen          87          2018-06-11           2018-06-18           2018-06-18           
95  ruuvi    autogen          95          2018-06-18           2018-06-25           2018-06-25           
103 ruuvi    autogen          103         2018-06-25           2018-07-02           2018-07-02           
111 ruuvi    autogen          111         2018-07-02           2018-07-09           2018-07-09           
119 ruuvi    autogen          119         2018-07-09           2018-07-16           2018-07-16           
126 ruuvi    autogen          126         2018-07-16           2018-07-23           2018-07-23           
135 ruuvi    autogen          135         2018-07-23           2018-07-30           2018-07-30           
143 ruuvi    autogen          143         2018-07-30           2018-08-06           2018-08-06           

151 ruuvi    autogen          151         2018-08-06           2018-08-13           2018-08-13           
159 ruuvi    autogen          159         2018-08-13           2018-08-20           2018-08-20           
167 ruuvi    autogen          167         2018-08-20           2018-08-27           2018-08-27           
175 ruuvi    autogen          175         2018-08-27           2018-09-03           2018-09-03           

183 ruuvi    autogen          183         2018-09-03           2018-09-10           2018-09-10           
191 ruuvi    autogen          191         2018-09-10           2018-09-17           2018-09-17           
199 ruuvi    autogen          199         2018-09-17           2018-09-24           2018-09-24           
204 ruuvi    autogen          204         2018-09-24           2018-10-01           2018-10-01           

212 ruuvi    autogen          212         2018-10-01           2018-10-08           2018-10-08           
219 ruuvi    autogen          219         2018-10-08           2018-10-15           2018-10-15           
227 ruuvi    autogen          227         2018-10-15           2018-10-22           2018-10-22           
230 ruuvi    autogen          230         2018-10-22           2018-10-29           2018-10-29           
239 ruuvi    autogen          239         2018-10-29           2018-11-05           2018-11-05           

247 ruuvi    autogen          247         2018-11-05           2018-11-12           2018-11-12           
255 ruuvi    autogen          255         2018-11-12           2018-11-19           2018-11-19           
263 ruuvi    autogen          263         2018-11-19           2018-11-26           2018-11-26           
271 ruuvi    autogen          271         2018-11-26           2018-12-03           2018-12-03           

278 ruuvi    autogen          278         2018-12-03           2018-12-10           2018-12-10           
286 ruuvi    autogen          286         2018-12-10           2018-12-17           2018-12-17           
294 ruuvi    autogen          294         2018-12-17           2018-12-24           2018-12-24           
302 ruuvi    autogen          302         2018-12-24           2018-12-31           2018-12-31           
310 ruuvi    autogen          310         2018-12-31           2019-01-07           2019-01-07           

318 ruuvi    autogen          318         2019-01-07           2019-01-14           2019-01-14           
326 ruuvi    autogen          326         2019-01-14           2019-01-21           2019-01-21           
334 ruuvi    autogen          334         2019-01-21           2019-01-28           2019-01-28           
342 ruuvi    autogen          342         2019-01-28           2019-02-04           2019-02-04           

350 ruuvi    autogen          350         2019-02-04           2019-02-11           2019-02-11           
358 ruuvi    autogen          358         2019-02-11           2019-02-18           2019-02-18           
366 ruuvi    autogen          366         2019-02-18           2019-02-25           2019-02-25           
374 ruuvi    autogen          374         2019-02-25           2019-03-04           2019-03-04           

382 ruuvi    autogen          382         2019-03-04           2019-03-11           2019-03-11           
390 ruuvi    autogen          390         2019-03-11           2019-03-18           2019-03-18           
398 ruuvi    autogen          398         2019-03-18           2019-03-25           2019-03-25           
406 ruuvi    autogen          406         2019-03-25           2019-04-01           2019-04-01           

414 ruuvi    autogen          414         2019-04-01           2019-04-08           2019-04-08           
422 ruuvi    autogen          422         2019-04-08           2019-04-15           2019-04-15           
430 ruuvi    autogen          430         2019-04-15           2019-04-22           2019-04-22           
438 ruuvi    autogen          438         2019-04-22           2019-04-29           2019-04-29           
448 ruuvi    autogen          448         2019-04-29           2019-05-06           2019-05-06           

458 ruuvi    autogen          458         2019-05-06           2019-05-13           2019-05-13           
468 ruuvi    autogen          468         2019-05-13           2019-05-20           2019-05-20           
476 ruuvi    autogen          476         2019-05-20           2019-05-27           2019-05-27           
486 ruuvi    autogen          486         2019-05-27           2019-06-03           2019-06-03           
496 ruuvi    autogen          496         2019-06-03           2019-06-10           2019-06-10           
506 ruuvi    autogen          506         2019-06-10           2019-06-17           2019-06-17           
516 ruuvi    autogen          516         2019-06-17           2019-06-24           2019-06-24           
526 ruuvi    autogen          526         2019-06-24           2019-07-01           2019-07-01           

 create retention policy half_yr on ruuvi DURATION 180d  REPLICATION 1 SHARD DURATION 7d   6/24/19 17:50

SHOW RETENTION POLICIES on ruuvi
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 0s        168h0m0s           1        true
half_yr 4320h0m0s 168h0m0s           1        false


 > df
/ 170MB    /varnew 2,398MB 


alter retention policy half_yr on ruuvi DURATION 180d  REPLICATION 1 SHARD DURATION 7d default
Mon Jun 24 18:10:06 

SHOW RETENTION POLICIES on ruuvi
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 0s        168h0m0s           1        false
half_yr 4320h0m0s 168h0m0s           1        true



!!>> shards before 302 are gone!

 df
/ 170MB    /varnew 2,467MB   ( +69MB free)

du /varnew/lib/influxdb/data/ruuvi/autogen 
560396

CREATE RETENTION POLICY "rp-1h"   ON "db1" DURATION 1h    REPLICATION 1 SHARD DURATION 2m
retention check-interval to run every 5 minutes so    


SELECT MAX(numSeries) AS numSeries FROM "database" WHERE "database" = 'db1' AND tmpltime() GROUP BY time(1m)



 6/24/19 

 select mac,first(temperature) from ruuvi_measurements tz('America/New_York') 
name: ruuvi_measurements
time                          mac          first
----                          ---          -----
2018-03-24T20:23:19.564-04:00 D3517872EC0F 5


select  count(temperature) from ruuvi_measurements where time < '2018-03-25' group by mac tz('America/New_York') 
name: ruuvi_measurements
tags: mac=D3517872EC0F
time                      count
----                      -----
1969-12-31T19:00:00-05:00 1152

name: ruuvi_measurements
tags: mac=F2C0C643AD03
time                      count
----                      -----
1969-12-31T19:00:00-05:00 1154

name: ruuvi_measurements
tags: mac=F7FA744A1E1A
time                      count
----                      -----
1969-12-31T19:00:00-05:00 1152




22256   ./log/kapacitor

37025   ./lib/influxdb/data/telegraf/autogen
37092   ./lib/influxdb/data/telegraf 

23977   ./lib/influxdb/data2

28728   ./lib/influxdb/wal/_internal/monitor/525
29349   ./lib/influxdb/wal/_internal/monitor
29352   ./lib/influxdb/wal/_internal

64266   ./lib/influxdb/data/_internal/monitor
65177   ./lib/influxdb/data/_internal


53303   ./lib/influxdb/wal/ruuvi/autogen
53307   ./lib/influxdb/wal/ruuvi
95554   ./lib/influxdb/wal

21908   ./lib/influxdb/data/ruuvi/autogen/334
22076   ./lib/influxdb/data/ruuvi/autogen/326
22436   ./lib/influxdb/data/ruuvi/autogen/350
24436   ./lib/influxdb/data/ruuvi/autogen/310
24784   ./lib/influxdb/data/ruuvi/autogen/318
24472   ./lib/influxdb/data/ruuvi/autogen/342
22792   ./lib/influxdb/data/ruuvi/autogen/430
24092   ./lib/influxdb/data/ruuvi/autogen/448
34052   ./lib/influxdb/data/ruuvi/autogen/468
40252   ./lib/influxdb/data/ruuvi/autogen/476   2019-05-20           2019-05-27 
42424   ./lib/influxdb/data/ruuvi/autogen/458
26024   ./lib/influxdb/data/ruuvi/autogen/486
23456   ./lib/influxdb/data/ruuvi/autogen/496
22976   ./lib/influxdb/data/ruuvi/autogen/506
20392   ./lib/influxdb/data/ruuvi/autogen/516

567532  ./lib/influxdb/data/ruuvi/autogen
567599  ./lib/influxdb/data/ruuvi
670337  ./lib/influxdb/data
789880  ./lib/influxdb
1254381 ./lib
From top
 VIRT   RES      SHR
1626004 191088   9860 S 69.4 43.1 359:09.77 influxd  


show SERIES key --- ruuvi_measurements,dataFormat=3,mac=DFC8B0FE5CC0 ruuvi_measurements,dataFormat=3,mac=E6C3BE6F656C ruuvi_measurements,dataFormat=3,mac=F7FA744A1E1A ruuvi_measurements,dataFormat=3,mac=FB0ECBEF7354 ruuvi_measurements,dataFormat=4,mac=D3517872EC0F ruuvi_measurements,dataFormat=4,mac=F2C0C643AD03 ruuvi_measurements,dataFormat=5,mac=E511D11ECBB8 ruuvi_measurements,dataFormat=5,mac=E6C3BE6F656C show FIELD KEYS name: ruuvi_measurements fieldKey fieldType -------- --------- absoluteHumidity float accelerationAngleFromX float accelerationAngleFromY float accelerationAngleFromZ float accelerationTotal float accelerationX float accelerationY float accelerationZ float airDensity float batteryVoltage float dewPoint float equilibriumVaporPressure float humidity float measurementSequenceNumber integer movementCounter integer pressure float rssi integer temperature float txPower integer docs.influxdata.com functions
[meta] dir = "/var/lib/influxdb/meta" retention-autocreate = true logging-enabled = true [data] dir = "/var/lib/influxdb/data" index-version = "inmem" wal-dir = "/var/lib/influxdb/wal" wal-fsync-delay = "5s" validate-keys = false query-log-enabled = true cache-max-memory-size = 1073741824 #1,073,741,824 1GB too big cache-snapshot-memory-size = 26214400 cache-snapshot-write-cold-duration = "10m0s" compact-full-write-cold-duration = "4h0m0s" compact-throughput = 50331648 compact-throughput-burst = 50331648 max-series-per-database = 1000000 max-values-per-tag = 100000 max-concurrent-compactions = 0 max-index-log-file-size = 1048576 trace-logging-enabled = false tsm-use-madv-willneed = false [coordinator] write-timeout = "10s" max-concurrent-queries = 0 query-timeout = "8s" log-queries-after = "0s" max-select-point = 0 max-select-series = 0 max-select-buckets = 0 [retention] enabled = true check-interval = "30m0s" [shard-precreation] enabled = true check-interval = "10m0s" advance-period = "30m0s" [monitor] store-enabled = true store-database = "_internal" store-interval = "10s" [subscriber] enabled = true http-timeout = "30s" insecure-skip-verify = false ca-certs = "" write-concurrency = 40 write-buffer-size = 1000 [http] enabled = true bind-address = ":8086" auth-enabled = false log-enabled = true suppress-write-log = false write-tracing = false flux-enabled = false [logging] format = "auto" level = "error" suppress-logo = false [[udp]] enabled = false bind-address = ":8089" database = "udp" retention-policy = "" batch-size = 5000 batch-pending = 10 read-buffer = 0 batch-timeout = "1s" precision = "" [continuous_queries] log-enabled = true enabled = true query-stats-enabled = false run-interval = "1s" [tls] min-version = "" max-version = ""
When creating a new DEFAULT retention policy(even if it is longer), data written to the old DEFAULT RP remain in the old RP.
Queries that do not specify an RP query the new DEFAULT RP so the old data appears to be missing.
To query the old data fully qualify the relevant data in the query.
CREATE RETENTION POLICY stats_30_day ON server_stats DURATION 30d REPLICATION 1 

ALTER  RETENTION POLICY stats_30_day ON server_stats DURATION 30d REPLICATION 1 default

ALTER RETENTION POLICY default ON ruuvi DURATION 380d 

community influxData

from raspberry pi rev B as of 18-12-14 InfluxDB shell version: 1.0.2
from pi zero 3/27/19 InfluxDB shell version: 1.7.4 , `

simplifying-influxdb-shards-and-retention-policies

influx_inspect