From df0b394c5973e524cfab02bc404288533da8dcd7 Mon Sep 17 00:00:00 2001 From: Itz-Agasta Date: Thu, 6 Aug 2026 14:32:07 +0530 Subject: [PATCH] Drop the place_classtype tables on migration Nothing creates or reads them anymore, so a migrated database would keep carrying them around for nothing. On a planet that is 428 tables and a good 8GB. The migration runs after the POI backfill, which still needs the table names to work out which rows to fill in. --- docs/admin/Migration.md | 12 ++++++++++++ src/nominatim_db/tools/migration.py | 19 ++++++++++++++++++- src/nominatim_db/version.py | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/admin/Migration.md b/docs/admin/Migration.md index da44c07f..3b8ebc2f 100644 --- a/docs/admin/Migration.md +++ b/docs/admin/Migration.md @@ -17,6 +17,18 @@ breaking changes. **Please read them before running the migration.** and migrate to 4.3 first. Then you can migrate to the current version. It is strongly recommended to do a reimport instead. +## 5.3.0 -> 5.4.0 + +### Removal of the place_classtype tables + +Category search now runs against the `categories` column of `placex`, so the +per-category `place_classtype_*` tables are not used anymore. The migration +drops them. This frees a considerable amount of disk space on a planet +database but may take a moment as there is one table per category. + +The `--min` option of `nominatim special-phrases` only restricted which of +those tables were created. It has no effect anymore and has been removed. + ## 5.2.0 -> 5.3.0 #### Expensive table migrations diff --git a/src/nominatim_db/tools/migration.py b/src/nominatim_db/tools/migration.py index 5fb88345..b2722141 100644 --- a/src/nominatim_db/tools/migration.py +++ b/src/nominatim_db/tools/migration.py @@ -13,7 +13,7 @@ import logging from ..errors import UsageError from ..config import Configuration from ..db import properties -from ..db.connection import connect, Connection, \ +from ..db.connection import connect, Connection, drop_tables, \ table_exists, register_hstore, table_has_column from ..db.sql_preprocessor import SQLPreprocessor from ..version import NominatimVersion, NOMINATIM_VERSION, parse_version @@ -684,3 +684,20 @@ def add_centroid_categories_index(conn: Connection, **_: Any) -> None: conn.execute("""CREATE INDEX IF NOT EXISTS idx_placex_centroid_categories ON placex USING GIST (centroid, categories gist__ltree_ops(siglen=8))""") + + +@_migration(5, 3, 99, 4) +def drop_place_classtype_tables(conn: Connection, **_: Any) -> None: + """ Drop the obsolete place_classtype_* tables. + + Category search now goes through the ltree categories column, so nothing + reads these tables anymore. They are dropped after the POI backfill above, + which still uses their names to decide which rows to fill in. + """ + with conn.cursor() as cur: + cur.execute("""SELECT tablename FROM pg_tables + WHERE schemaname = 'public' + AND tablename LIKE 'place\\_classtype\\_%'""") + tables = [row[0] for row in cur] + + drop_tables(conn, *tables) diff --git a/src/nominatim_db/version.py b/src/nominatim_db/version.py index 3a2c83ad..e512d216 100644 --- a/src/nominatim_db/version.py +++ b/src/nominatim_db/version.py @@ -55,7 +55,7 @@ def parse_version(version: str) -> NominatimVersion: return NominatimVersion(*[int(x) for x in parts[:2] + parts[2].split('-')]) -NOMINATIM_VERSION = parse_version('5.3.99-3') +NOMINATIM_VERSION = parse_version('5.3.99-4') POSTGRESQL_REQUIRED_VERSION = (13, 0) POSTGIS_REQUIRED_VERSION = (3, 0) -- 2.47.3