bigtables.py
changeset 83 515fadd3d286
parent 38 d3593869d624
child 93 b72591087495
equal deleted inserted replaced
82:7b82dc1fb6f5 83:515fadd3d286
     1 #!/usr/bin/env python3.2
     1 #!/usr/bin/env python3.2
     2 
     2 
     3 from pgtoolkit import pgbrowser, toolbase, prettysize
     3 from pgtoolkit import pgbrowser, toolbase
       
     4 from pycolib import prettysize
     4 
     5 
     5 
     6 
     6 class BigTablesTool(toolbase.SimpleTool):
     7 class BigTablesTool(toolbase.SimpleTool):
     7     def __init__(self):
     8     def __init__(self):
     8         toolbase.SimpleTool.__init__(self, name='bigtables', desc='List largest tables.')
     9         toolbase.SimpleTool.__init__(self, name='bigtables', desc='List largest tables.')
    17         for schema in schemas:
    18         for schema in schemas:
    18             tables = browser.list_tables(schema['name'])
    19             tables = browser.list_tables(schema['name'])
    19             for table in tables:
    20             for table in tables:
    20                 table_name = '%s.%s' % (schema['name'], table['name'])
    21                 table_name = '%s.%s' % (schema['name'], table['name'])
    21                 all_tables.append({'name': table_name, 'size': table['size']})
    22                 all_tables.append({'name': table_name, 'size': table['size']})
    22         
    23 
    23         # print names and sizes of 20 largest tables
    24         # print names and sizes of 20 largest tables
    24         for table in sorted(all_tables, reverse=True, key=lambda x: x['size'])[:20]:
    25         for table in sorted(all_tables, reverse=True, key=lambda x: x['size'])[:20]:
    25             print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
    26             print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
    26 
    27 
    27 
    28