2
|
1 |
#!/usr/bin/env python3.2
|
|
2 |
|
|
3 |
from pgtools import pgbrowser
|
|
4 |
from common import prettysize
|
5
|
5 |
from toolbase import SimpleTool
|
2
|
6 |
|
|
7 |
|
5
|
8 |
class BigTablesTool(SimpleTool):
|
2
|
9 |
def __init__(self):
|
5
|
10 |
SimpleTool.__init__(self, name='bigtables', desc='List largest tables.')
|
2
|
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 |
|