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 tasks')
24 objs = group.add_mutually_exclusive_group(required=True)
25 objs.add_argument('--warm', action='store_true',
26 help='Warm database caches for search and reverse queries.')
27 objs.add_argument('--check-database', action='store_true',
28 help='Check that the database is complete and operational.')
29 objs.add_argument('--migrate', action='store_true',
30 help='Migrate the database to a new software version.')
31 objs.add_argument('--analyse-indexing', action='store_true',
32 help='Print performance analysis of the indexing process.')
33 group = parser.add_argument_group('Arguments for cache warming')
34 group.add_argument('--search-only', action='store_const', dest='target',
36 help="Only pre-warm tables for search queries")
37 group.add_argument('--reverse-only', action='store_const', dest='target',
39 help="Only pre-warm tables for reverse queries")
40 group = parser.add_argument_group('Arguments for index anaysis')
41 mgroup = group.add_mutually_exclusive_group()
42 mgroup.add_argument('--osm-id', type=str,
43 help='Analyse indexing of the given OSM object')
44 mgroup.add_argument('--place-id', type=int,
45 help='Analyse indexing of the given Nominatim object')
50 return AdminFuncs._warm(args)
52 if args.check_database:
53 LOG.warning('Checking database')
54 from ..tools import check_database
55 return check_database.check_database(args.config)
57 if args.analyse_indexing:
58 LOG.warning('Analysing performance of indexing function')
59 from ..tools import admin
60 with connect(args.config.get_libpq_dsn()) as conn:
61 admin.analyse_indexing(conn, osm_id=args.osm_id, place_id=args.place_id)
65 LOG.warning('Checking for necessary database migrations')
66 from ..tools import migration
67 return migration.migrate(args.config, args)
74 LOG.warning('Warming database caches')
76 if args.target == 'reverse':
77 params.append('--reverse-only')
78 if args.target == 'search':
79 params.append('--search-only')
80 return run_legacy_script(*params, nominatim_env=args)