bigtables.py
changeset 2 efee419b7a2d
child 5 57cf8fdff5ed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bigtables.py	Mon Jul 18 17:39:37 2011 +0200
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3.2
+
+from pgtools import pgbrowser
+from common import prettysize
+from toolbase import ToolBase
+
+
+class BigTablesTool(ToolBase):
+    def __init__(self):
+        ToolBase.__init__(self, name='bigtables', desc='List largest tables.')
+        self.init()
+
+    def main(self):
+        browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
+
+        tables = browser.list_tables()
+        for table in sorted(tables, reverse=True, key=lambda x: x['size'])[:20]:
+            print(prettysize.prettysize_short(table['size']).rjust(8), table['name'], sep='  ')
+
+
+tool = BigTablesTool()
+tool.main()
+