InfluxDB not write data when I specified retention policy

Hi
I’m a new user of InfluxDB so it is possible than I don’t understand some concepts.
I have several measurements and I have created two retention policies because I want a different storage duration beetwen the differents measurements.

> show retention policies on homebd
name    duration   shardGroupDuration replicaN default
----    --------   ------------------ -------- -------
30jours 720h0m0s   24h0m0s            1        false
2ans    17520h0m0s 168h0m0s           1        true

But the data were not written when I tried to write them with the retention policy “30jours”:

curl -i -XPOST 'http://localhost:8086/write?db=homebd&rp=30jours' --data-binary 'sensor_porte_entree contact=1'
    HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 92158dee-5188-11ea-8024-0242ac130004
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.9
X-Request-Id: 92158dee-5188-11ea-8024-0242ac130004
Date: Mon, 17 Feb 2020 13:22:39 GMT

When I querie measurement “sensor_porte_entree”, I have nothing:

> select * from sensor_porte_entree
> 

But if I write data with the other retention policy (the default one) it is OK.

curl -i -XPOST 'http://localhost:8086/write?db=homebd&rp=2ans' --data-binary 'sensor_porte_entree contact=1'
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: e499073a-518d-11ea-8185-0242ac130004
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.7.9
X-Request-Id: e499073a-518d-11ea-8185-0242ac130004
Date: Mon, 17 Feb 2020 14:00:45 GMT

Result:

> select * from sensor_porte_entree
name: sensor_porte_entree
time                           contact
----                           -------
2020-02-17T14:00:45.569485502Z 1
> 

So is it possible to use several retention policies in the same database and use one of them as I want to write data in measurements?

Hi, yep. Most people would do this to aggregate their data. KEep the raw data for 30 days and down sample it into a longer retention policy.

When you connect to the influx CLI you need to specify the RP you want to use, the default one is usually selected.

if you type use yourdatabase.the_RP_you_want Inside the Influx CLI then run your query you should see your data. To set the default policy to write your metrics, inside the telegraf configuration under the connection details there should be an option to set the default RP. Un commenting this

# retention_policy = "" and setting your RP in there will send the data to that RP.

Regarding working with multiple retention policies this should help

OK many thanks, it was the influx CLI default RP selection. Then I understand it is not easy to manage storage duration with this method. In particularly how select RP “30jours” when I visualise data in Grafana?

I found it in the graphical editor of the query of Grafana
Thanks

Yep, you should be able to select all retention policies on that database - I think there is a way to set up template variables to switch the retention policy on a dashboard. Can’t quite remember though.