diff --git a/.typos.toml b/.typos.toml index ea78907a..268764e6 100644 --- a/.typos.toml +++ b/.typos.toml @@ -13,6 +13,7 @@ dur = "dur" pn = "pn" Derivated = "Derivated" Bre = "Bre" +BRIN = "BRIN" [type.po] extend-glob = ["*.po"] diff --git a/CHANGELOG.md b/CHANGELOG.md index af45c21f..22131819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/priv/repo/migrations/20251225150000_replace_positions_date_indexes.exs b/priv/repo/migrations/20251225150000_replace_positions_date_indexes.exs new file mode 100644 index 00000000..f67b1378 --- /dev/null +++ b/priv/repo/migrations/20251225150000_replace_positions_date_indexes.exs @@ -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 diff --git a/website/docs/import/teslafi.md b/website/docs/import/teslafi.md index 5209ce5e..7b578a28 100644 --- a/website/docs/import/teslafi.md +++ b/website/docs/import/teslafi.md @@ -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.