Author: poeml Date: Fri Dec 4 22:33:01 2009 New Revision: 7902 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=7902&view=rev Log: mb vacuum: - new --size option, which shows the size of all database relation, including total size in megabytes. Should be quite helpful for database tuning. Modified: trunk/mirrordoctor/mb/vacuum.py trunk/mirrordoctor/mirrordoctor.py Modified: trunk/mirrordoctor/mb/vacuum.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mb/vacuum.py?rev=7902&r1=7901&r2=7902&view=diff ============================================================================== --- trunk/mirrordoctor/mb/vacuum.py (original) +++ trunk/mirrordoctor/mb/vacuum.py Fri Dec 4 22:33:01 2009 @@ -21,3 +21,24 @@ print 'Done.' + +def dbstats(conn): + """show statistics about stale files in the database""" + + query = """SELECT relname, relkind, relfilenode, reltuples, relpages, + relpages*8 AS relMB + FROM pg_class + WHERE relkind IN ('r', 'i') + AND relname ~ '^.*(file|server|pfx|temp1).*' + ORDER BY 1""" + rows = conn.Filearr._connection.queryAll(query) + + print 'Size(MB) Relation' + total = 0 + for row in rows: + name, kind, filenode, tuples, pages, size = row + sizeMB = float(size) / 1024 + total += sizeMB + print '%5.1f %s' % (sizeMB, name) + + print 'Total: %.1f' % total Modified: trunk/mirrordoctor/mirrordoctor.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mirrordoctor/mirrordoctor.py?rev=7902&r1=7901&r2=7902&view=diff ============================================================================== --- trunk/mirrordoctor/mirrordoctor.py (original) +++ trunk/mirrordoctor/mirrordoctor.py Fri Dec 4 22:33:01 2009 @@ -820,14 +820,25 @@ mirror.score = int(score) + @cmdln.option('--size', action='store_true', + help='don\'t delete, but show how much size the database uses.') @cmdln.option('-n', '--dry-run', action='store_true', help='don\'t delete, but only show statistics.') def do_vacuum(self, subcmd, opts, *args): - """${cmd_name}: clean up unreferenced files from the mirror database - - This should be done once a week for a busy file tree. - Otherwise it should be rarely needed, but can possibly - improve performance if it is able to shrink the database. + """${cmd_name}: perform database maintenance + + If called without further argumets, the command cleans up unreferenced + files from the mirror database. + This should be done once a week for a busy file tree. Otherwise it + should be rarely needed, but can possibly improve performance if it is + able to shrink the database. + + When called with the -n option, only the number of files to be cleaned + up is printed. This is purely for information. + + When called with the --size option, the size of each database relation + will be preinted, which can provide insight for the appropriate + database tuning. ${cmd_usage} ${cmd_option_list} @@ -835,9 +846,12 @@ import mb.vacuum - mb.vacuum.stale(self.conn) - if not opts.dry_run: - mb.vacuum.vacuum(self.conn) + if opts.size: + mb.vacuum.dbstats(self.conn) + else: + mb.vacuum.stale(self.conn) + if not opts.dry_run: + mb.vacuum.vacuum(self.conn) @cmdln.option('-u', '--url', action='store_true', _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Fri Dec 04 2009 - 21:33:05 GMT
This archive was generated by hypermail 2.2.0 : Fri Dec 04 2009 - 21:45:13 GMT