16 def __init__(self): |
16 def __init__(self): |
17 toolbase.SimpleTool.__init__(self, name='analyzeall', desc='Analyze all tables.') |
17 toolbase.SimpleTool.__init__(self, name='analyzeall', desc='Analyze all tables.') |
18 self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter') |
18 self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter') |
19 self.parser.add_argument('--vacuum', action='store_true', help='Call VACUUM ANALYZE') |
19 self.parser.add_argument('--vacuum', action='store_true', help='Call VACUUM ANALYZE') |
20 self.parser.add_argument('--full', action='store_true', help='Call VACUUM FULL ANALYZE') |
20 self.parser.add_argument('--full', action='store_true', help='Call VACUUM FULL ANALYZE') |
|
21 self.parser.add_argument('--reindex', action='store_true', help='Call REINDEX TABLE') |
21 self.target_isolation_level = 'autocommit' |
22 self.target_isolation_level = 'autocommit' |
22 self.init() |
23 self.init() |
23 |
24 |
24 def main(self): |
25 def main(self): |
25 browser = pgbrowser.PgBrowser(self.pgm.get_conn('target')) |
26 browser = pgbrowser.PgBrowser(self.pgm.get_conn('target')) |
26 |
27 |
27 query_pattern = 'ANALYZE %s.%s;' |
28 query_pattern = 'ANALYZE %s.%s;' |
28 if self.args.vacuum: |
29 if self.args.vacuum: |
29 query_pattern = 'VACUUM ANALYZE %s.%s;' |
30 query_pattern = 'VACUUM ANALYZE %s.%s;' |
30 if self.args.full: |
31 if self.args.full: |
31 query_pattern = 'VACUUM FULL ANALYZE %s.%s;' |
32 query_pattern = 'VACUUM FULL ANALYZE %s.%s;' |
|
33 if self.args.reindex: |
|
34 query_pattern = 'REINDEX TABLE %s.%s;' |
32 |
35 |
33 schema_list = self.args.schema |
36 schema_list = self.args.schema |
34 if not schema_list: |
37 if not schema_list: |
35 schema_list = [schema['name'] for schema in browser.list_schemas() if not schema['system']] |
38 schema_list = [schema['name'] for schema in browser.list_schemas() if not schema['system']] |
36 |
39 |
37 for schema in schema_list: |
40 for schema in schema_list: |
38 tables = browser.list_tables(schema=schema) |
41 tables = browser.list_tables(schema=schema) |
39 with self.pgm.cursor('target') as curs: |
42 with self.pgm.cursor('target') as curs: |
40 for table in tables: |
43 for table in tables: |
41 query = query_pattern % (schema, table['name']) |
44 query = query_pattern % (schema, table['name']) |
42 print(query) |
45 self.log.info(query) |
43 curs.execute(query, []) |
46 curs.execute(query, []) |
44 |
47 |
45 |
48 |
46 tool = AnalyzeAllTool() |
49 tool = AnalyzeAllTool() |
47 tool.main() |
50 tool.main() |