bigtables.py
changeset 38 d3593869d624
parent 9 2fcc8ef0b97d
child 83 515fadd3d286
equal deleted inserted replaced
37:5b0eb4b11940 38:d3593869d624
     9         self.init()
     9         self.init()
    10 
    10 
    11     def main(self):
    11     def main(self):
    12         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
    12         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
    13 
    13 
    14         tables = browser.list_tables()
    14         # scan all tables from all shemas, remember names and sizes
    15         for table in sorted(tables, reverse=True, key=lambda x: x['size'])[:20]:
    15         all_tables = []
       
    16         schemas = browser.list_schemas()
       
    17         for schema in schemas:
       
    18             tables = browser.list_tables(schema['name'])
       
    19             for table in tables:
       
    20                 table_name = '%s.%s' % (schema['name'], table['name'])
       
    21                 all_tables.append({'name': table_name, 'size': table['size']})
       
    22         
       
    23         # print names and sizes of 20 largest tables
       
    24         for table in sorted(all_tables, reverse=True, key=lambda x: x['size'])[:20]:
    16             print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
    25             print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
    17 
    26 
    18 
    27 
    19 tool = BigTablesTool()
    28 tool = BigTablesTool()
    20 tool.main()
    29 tool.main()