第一步:下载influx CLI
Download the influx CLI package.
https://docs.influxdata.com/influxdb/v2/tools/influx-cli/?t=Windows
第二步:设置influx CLI
F:\tools\influxdb2-client-2.7.5-windows-amd64> influx config create --config-name config --host-url http://localhost:8086 --org myorg --token 34j18h5hZFVE27FinsZ9rQVBka62EnnmEHL_6Lp0rzQ_IHgZavMthFAKgVrA05RsHXNQO0Ozlr3lF3ubDoCT4Q== --active
 
第三步:修改保留策略时间
-- 列出所有的buckets
influx bucket list
F:\tools\influxdb2-client-2.7.5-windows-amd64>influx bucket list
ID                      Name            Retention       Shard group duration    Organization ID         Schema Type
069af8ca95cb6687        smaple          infinite        168h0m0s                a17eb7759879d6e0        implicit
-- 修改保留策略为最近两年(730d)
influx bucket update --id <bucket-id> --retention 730d
例如:更新此bucket过期时间为365天
influx bucket update \ 
  --id 4c9a0159cfb9186d \ 
  --retention 365d \ 
  --token your-auth-token
说明:
- 配置变更立即生效(对新数据)
 一旦您运行了 influx bucket update -r ,这个新的保留策略会立即应用到后续写入的数据。
 所有新写入的数据将遵循新的过期规则。
 🔹 例如:你把保留时间从 30d 改为 7d,那么从修改之后写入的所有数据,将在 7 天后过期。
- 旧数据的清理是异步进行的(延迟生效)
 已存在的、超出新保留期限的数据不会马上被删除。
 InfluxDB 有一个后台任务(Retention Enforcement Service),它会周期性地检查并删除过期的数据。
 默认检查间隔:
 每 30 分钟检查一次(由配置项 retention-check-interval = "30m" 控制)。
 因此,最坏情况下,超出保留时间的数据可能最多再保留 30 分钟才会被清理。