Update analyzeall tool: Allow combination of vacuum and reindex.
authorRadek Brich <radek.brich@devl.cz>
Tue, 24 Sep 2013 13:34:17 +0200
changeset 88 b8b2d28a7f35
parent 87 3ef717ee9253
child 89 6b72d61837b1
Update analyzeall tool: Allow combination of vacuum and reindex.
analyzeall.py
--- a/analyzeall.py	Tue Sep 24 13:34:15 2013 +0200
+++ b/analyzeall.py	Tue Sep 24 13:34:17 2013 +0200
@@ -16,7 +16,7 @@
         toolbase.SimpleTool.__init__(self, name='analyzeall', desc='Analyze all tables.')
         self.parser.add_argument('-s', dest='schema', nargs='*', help='Schema filter')
         self.parser.add_argument('--vacuum', action='store_true', help='Call VACUUM ANALYZE')
-        self.parser.add_argument('--full', action='store_true', help='Call VACUUM FULL ANALYZE')
+        self.parser.add_argument('--vacuum-full', action='store_true', help='Call VACUUM FULL ANALYZE')
         self.parser.add_argument('--reindex', action='store_true', help='Call REINDEX TABLE')
         self.target_isolation_level = 'autocommit'
         self.init()
@@ -24,13 +24,13 @@
     def main(self):
         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
 
-        query_pattern = 'ANALYZE %s.%s;'
+        query_patterns = ['ANALYZE %s.%s;']
         if self.args.vacuum:
-            query_pattern = 'VACUUM ANALYZE %s.%s;'
-        if self.args.full:
-            query_pattern = 'VACUUM FULL ANALYZE %s.%s;'
+            query_patterns = ['VACUUM ANALYZE %s.%s;']
+        if self.args.vacuum_full:
+            query_patterns = ['VACUUM FULL ANALYZE %s.%s;']
         if self.args.reindex:
-            query_pattern = 'REINDEX TABLE %s.%s;'
+            query_patterns += ['REINDEX TABLE %s.%s;']
 
         schema_list = self.args.schema
         if not schema_list:
@@ -40,9 +40,10 @@
             tables = browser.list_tables(schema=schema)
             with self.pgm.cursor('target') as curs:
                 for table in tables:
-                    query = query_pattern % (schema, table['name'])
-                    self.log.info(query)
-                    curs.execute(query, [])
+                    for query_pattern in query_patterns:
+                        query = query_pattern % (schema, table['name'])
+                        self.log.info(query)
+                        curs.execute(query, [])
 
 
 tool = AnalyzeAllTool()