X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6e89310a9285f1ad15d8002bf68f578eada367a0..adce7261ace1b4a21ea49805fb40ba5d50caef89:/src/nominatim_db/tools/admin.py?ds=inline diff --git a/src/nominatim_db/tools/admin.py b/src/nominatim_db/tools/admin.py index 7cc0f047..e70a7e50 100644 --- a/src/nominatim_db/tools/admin.py +++ b/src/nominatim_db/tools/admin.py @@ -10,13 +10,13 @@ Functions for database analysis and maintenance. from typing import Optional, Tuple, Any, cast import logging -from psycopg2.extras import Json, register_hstore -from psycopg2 import DataError +import psycopg +from psycopg.types.json import Json -from nominatim_core.typing import DictCursorResult -from nominatim_core.config import Configuration -from nominatim_core.db.connection import connect, Cursor -from nominatim_core.errors import UsageError +from ..typing import DictCursorResult +from ..config import Configuration +from ..db.connection import connect, Cursor, register_hstore +from ..errors import UsageError from ..tokenizer import factory as tokenizer_factory from ..data.place_info import PlaceInfo @@ -59,7 +59,7 @@ def analyse_indexing(config: Configuration, osm_id: Optional[str] = None, """ with connect(config.get_libpq_dsn()) as conn: register_hstore(conn) - with conn.cursor() as cur: + with conn.cursor(row_factory=psycopg.rows.dict_row) as cur: place = _get_place_info(cur, osm_id, place_id) cur.execute("update placex set indexed_status = 2 where place_id = %s", @@ -74,6 +74,9 @@ def analyse_indexing(config: Configuration, osm_id: Optional[str] = None, tokenizer = tokenizer_factory.get_tokenizer_for_db(config) + # Enable printing of messages. + conn.add_notice_handler(lambda diag: print(diag.message_primary)) + with tokenizer.name_analyzer() as analyzer: cur.execute("""UPDATE placex SET indexed_status = 0, address = %s, token_info = %s, @@ -86,9 +89,6 @@ def analyse_indexing(config: Configuration, osm_id: Optional[str] = None, # we do not want to keep the results conn.rollback() - for msg in conn.notices: - print(msg) - def clean_deleted_relations(config: Configuration, age: str) -> None: """ Clean deleted relations older than a given age @@ -101,6 +101,6 @@ def clean_deleted_relations(config: Configuration, age: str) -> None: WHERE p.osm_type = d.osm_type AND p.osm_id = d.osm_id AND age(p.indexed_date) > %s::interval""", (age, )) - except DataError as exc: + except psycopg.DataError as exc: raise UsageError('Invalid PostgreSQL time interval format') from exc conn.commit()