bigtables.py
changeset 2 efee419b7a2d
child 5 57cf8fdff5ed
equal deleted inserted replaced
0:eaae9539e910 2:efee419b7a2d
       
     1 #!/usr/bin/env python3.2
       
     2 
       
     3 from pgtools import pgbrowser
       
     4 from common import prettysize
       
     5 from toolbase import ToolBase
       
     6 
       
     7 
       
     8 class BigTablesTool(ToolBase):
       
     9     def __init__(self):
       
    10         ToolBase.__init__(self, name='bigtables', desc='List largest tables.')
       
    11         self.init()
       
    12 
       
    13     def main(self):
       
    14         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
       
    15 
       
    16         tables = browser.list_tables()
       
    17         for table in sorted(tables, reverse=True, key=lambda x: x['size'])[:20]:
       
    18             print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
       
    19 
       
    20 
       
    21 tool = BigTablesTool()
       
    22 tool.main()
       
    23