I have an InfluxDB 2 instance that I’m testing some stuff on. It doesn’t have backups but it did take some time to create, so I’d prefer if I didn’t have to recreate it completely from scratch, and especially I do not want the bucket ID to change because I’m using it on a lot of different devices.
I just made a mistake, I inserted a field as a string that was supposed to be a float. I immediately stopped InfluxDB.
My question is, can I go into the file system, find the data that was last inserted and manually delete it, so that the field name becomes available for a float field again?
I can see some data of the erroneously added datapoints in data/<bucket id>/_series/06/0000, data/<bucket id>/autogen/1104/fields.idx and wal/<bucket id>/autogen/_00004.wal.
But does that remove the field from the schema? The way I remember it, even if you delete all corresponding data points, the field type is forever frozen. That’s why I normally always double and triple check my field types because every mistake is permanent (unless I delete the bucket).
Does the field need to be named exactly as the currently inserted string-typed one? Maybe you could pick a different name and create a new one that has the correct type?
There’s still time to make compromises later when the database is in use, since I’m just setting it up I’d rather do it right.
What I ended up doing is this:
# Export the bucket into a file, up to a timestamp right before my mistake
docker exec influxdb2 influxd inspect export-lp --bucket-id [old-bucket-id] --output-path - --engine-path /var/lib/influxdb2/engine --end '2024-07-23T01:07:00.000Z' --compress > /root/influxdb-fuckup/dump.lp.gz
# Import the data into a new bucket
docker exec influxdb2 influx config create -a -u http://localhost:8086 -t [redacted] -n local
pv /root/influxdb-fuckup/dump.lp.gz | docker exec -i influxdb2 influx write --org-id [redacted] --bucket-id [new-bucket-id] --compression gzip
# Move the data from the new bucket into the old bucket
docker stop influxdb2
rm -r /opt/influxdb2/data/engine/data/[old-bucket]
rm -r /opt/influxdb2/data/engine/wal/[old-bucket]
cp -rp /opt/influxdb2/data/engine/data/[new-bucket] /opt/influxdb2/data/engine/data/[old-bucket]
cp -rp /opt/influxdb2/data/engine/wal/[new-bucket] /opt/influxdb2/data/engine/wal/[old-bucket]
docker start influxdb2