1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Functions for database analysis and maintenance.
12 from nominatim.errors import UsageError
14 LOG = logging.getLogger()
16 def analyse_indexing(conn, osm_id=None, place_id=None):
17 """ Analyse indexing of a single Nominatim object.
19 with conn.cursor() as cur:
21 osm_type = osm_id[0].upper()
22 if osm_type not in 'NWR' or not osm_id[1:].isdigit():
23 LOG.fatal('OSM ID must be of form <N|W|R><id>. Got: %s', osm_id)
24 raise UsageError("OSM ID parameter badly formatted")
25 cur.execute('SELECT place_id FROM placex WHERE osm_type = %s AND osm_id = %s',
26 (osm_type, osm_id[1:]))
29 LOG.fatal("OSM object %s not found in database.", osm_id)
30 raise UsageError("OSM object not found")
32 place_id = cur.fetchone()[0]
35 LOG.fatal("No OSM object given to index.")
36 raise UsageError("OSM object not found")
38 cur.execute("update placex set indexed_status = 2 where place_id = %s",
41 cur.execute("""SET auto_explain.log_min_duration = '0';
42 SET auto_explain.log_analyze = 'true';
43 SET auto_explain.log_nested_statements = 'true';
45 SET client_min_messages = LOG;
46 SET log_min_messages = FATAL""")
48 cur.execute("update placex set indexed_status = 0 where place_id = %s",
51 # we do not want to keep the results
54 for msg in conn.notices: