2 Functions for database analysis and maintenance.
 
   6 from nominatim.errors import UsageError
 
   8 LOG = logging.getLogger()
 
  10 def analyse_indexing(conn, osm_id=None, place_id=None):
 
  11     """ Analyse indexing of a single Nominatim object.
 
  13     with conn.cursor() as cur:
 
  15             osm_type = osm_id[0].upper()
 
  16             if osm_type not in 'NWR' or not osm_id[1:].isdigit():
 
  17                 LOG.fatal('OSM ID must be of form <N|W|R><id>. Got: %s', osm_id)
 
  18                 raise UsageError("OSM ID parameter badly formatted")
 
  19             cur.execute('SELECT place_id FROM placex WHERE osm_type = %s AND osm_id = %s',
 
  20                         (osm_type, osm_id[1:]))
 
  23                 LOG.fatal("OSM object %s not found in database.", osm_id)
 
  24                 raise UsageError("OSM object not found")
 
  26             place_id = cur.fetchone()[0]
 
  29             LOG.fatal("No OSM object given to index.")
 
  30             raise UsageError("OSM object not found")
 
  32         cur.execute("update placex set indexed_status = 2 where place_id = %s",
 
  35         cur.execute("""SET auto_explain.log_min_duration = '0';
 
  36                        SET auto_explain.log_analyze = 'true';
 
  37                        SET auto_explain.log_nested_statements = 'true';
 
  39                        SET client_min_messages = LOG;
 
  40                        SET log_min_messages = FATAL""")
 
  42         cur.execute("update placex set indexed_status = 0 where place_id = %s",
 
  45     # we do not want to keep the results
 
  48     for msg in conn.notices: