2 Implementation of the 'admin' subcommand.
6 from ..tools.exec_utils import run_legacy_script
7 from ..db.connection import connect
9 # Do not repeat documentation of subcommand classes.
10 # pylint: disable=C0111
11 # Using non-top-level imports to avoid eventually unused imports.
12 # pylint: disable=E0012,C0415
14 LOG = logging.getLogger()
18 Analyse and maintain the database.
23 group = parser.add_argument_group('Admin task arguments')
24 group.add_argument('--warm', action='store_true',
25 help='Warm database caches for search and reverse queries.')
26 group.add_argument('--check-database', action='store_true',
27 help='Check that the database is complete and operational.')
28 group.add_argument('--analyse-indexing', action='store_true',
29 help='Print performance analysis of the indexing process.')
30 group = parser.add_argument_group('Arguments for cache warming')
31 group.add_argument('--search-only', action='store_const', dest='target',
33 help="Only pre-warm tables for search queries")
34 group.add_argument('--reverse-only', action='store_const', dest='target',
36 help="Only pre-warm tables for reverse queries")
37 group = parser.add_argument_group('Arguments for index anaysis')
38 mgroup = group.add_mutually_exclusive_group()
39 mgroup.add_argument('--osm-id', type=str,
40 help='Analyse indexing of the given OSM object')
41 mgroup.add_argument('--place-id', type=int,
42 help='Analyse indexing of the given Nominatim object')
47 AdminFuncs._warm(args)
49 if args.check_database:
50 LOG.warning('Checking database')
51 from ..tools import check_database
52 return check_database.check_database(args.config)
54 if args.analyse_indexing:
55 LOG.warning('Analysing performance of indexing function')
56 from ..tools import admin
57 with connect(args.config.get_libpq_dsn()) as conn:
58 admin.analyse_indexing(conn, osm_id=args.osm_id, place_id=args.place_id)
65 LOG.warning('Warming database caches')
67 if args.target == 'reverse':
68 params.append('--reverse-only')
69 if args.target == 'search':
70 params.append('--search-only')
71 return run_legacy_script(*params, nominatim_env=args)