perf: Replace positions indexes from BTREE to BRIN to reduce memory usage (#5075)

* Replace positions indexes

* Update .typos.toml

* Update teslafi.md

* docs: update changelog

---------

Co-authored-by: Jakob Lichterfeld <jakob-lichterfeld@gmx.de>
This commit is contained in:
Ilya Y
2026-01-08 14:30:18 +01:00
committed by GitHub
parent 4fc7272eb6
commit 0bf84dfc2b
4 changed files with 16 additions and 0 deletions
+1
View File
@@ -13,6 +13,7 @@ dur = "dur"
pn = "pn"
Derivated = "Derivated"
Bre = "Bre"
BRIN = "BRIN"
[type.po]
extend-glob = ["*.po"]
+1
View File
@@ -8,6 +8,7 @@
- feat: use Logger instead of IO.puts in DB check (#5050 - @swiffer)
- feat: Increase max_header_value_length to support oauth2-proxy (#5031 - @ultravail)
- perf: Replace positions indexes from BTREE to BRIN to reduce memory usage (#5075 - @ilya-y-synth)
#### Build, CI, internal
@@ -0,0 +1,13 @@
defmodule TeslaMate.Repo.Migrations.ReplaceDateBtreeIndexesWithBrin do
use Ecto.Migration
def change do
# Drop BTREE indexes
drop_if_exists(index(:positions, [:drive_id, :date]))
drop_if_exists(index(:positions, [:date]))
# Create BRIN indexes
create(index(:positions, [:date], using: "brin"))
create(index(:positions, [:drive_id, :date], using: "brin"))
end
end
+1
View File
@@ -220,6 +220,7 @@ go()
2. **Restart** the teslamate service and open the TeslaMate admin interface. Now the import form should be displayed instead of the vehicle summary.
3. Since the raw data is in the local timezone (assigned by the home address in the TeslaFi settings page) you need to **select your local timezone**. Then start the import. On low-end hardware like the Raspberry Pi, importing a large data set spanning several years will take a couple of hours.
4. After the import is complete, **empty the `import` directory** (or remove but ensure docker doesn't have a volume mapping) and **restart** the `teslamate` service.
5. Reindex PostgreSQL data: `REINDEX TABLE positions;`
:::note
If there is an overlap between the already existing TeslaMate and TeslaFi data, only the data prior to the first TeslaMate data will be imported.