Ticket #12451: optimizedb.diff
File optimizedb.diff, 2.4 KB (added by , 9 years ago) |
---|
-
.pl
old new 2 2 # 3 3 # Connects to the mythtv database and repairs/optimizes the tables that it 4 4 # finds. Suggested use is to cron it to run once per day. 5 # Timing additions by JP following http://www.perlmonks.org/?node_id=795716 5 6 # 6 7 # @url $URL$ 7 8 # @date $Date$ … … 13 14 # Includes 14 15 use DBI; 15 16 use MythTV; 17 use Time::HiRes qw( time ); # If required 18 19 # Setup timing stuff 20 my @t; 16 21 17 22 # Connect to mythbackend 18 23 my $Myth = new MythTV({'connect' => 0}); … … 22 27 23 28 # Repair and optimize each table 24 29 foreach $table ($dbh->tables) { 30 $t[0]= time(); 31 print "Working on: $table\n"; 25 32 unless ($dbh->do("REPAIR TABLE $table")) { 26 33 print "Skipped: $table\n"; 27 34 next; … … 32 39 if ($dbh->do("ANALYZE TABLE $table")) { 33 40 print "Analyzed: $table\n"; 34 41 } 42 $t[1]= time(); 43 my $diff = formatted_time_diff(@t); 44 print "Processing took $diff seconds\n"; 35 45 } 36 46 37 # Defragement seek table 47 # Defrag some big tables; see Ticket #12451 48 49 # Defragment seek table 50 $t[0]= time(); 51 print "Defragging: recordedseek\n"; 38 52 if ($dbh->do("ALTER TABLE `recordedseek` ORDER BY chanid, starttime, type")) { 39 53 print "Defragmented: recordedseek\n"; 54 $t[1]= time(); 55 my $diff = formatted_time_diff(@t); 56 print "Processing took $diff seconds\n"; 40 57 } 41 # Defragement program table 58 # Defragment program table 59 $t[0]= time(); 60 print "Defragging: program\n"; 42 61 if ($dbh->do("ALTER TABLE `program` ORDER BY starttime, chanid")) { 43 62 print "Defragmented: program\n"; 63 $t[1]= time(); 64 my $diff = formatted_time_diff(@t); 65 print "Processing took $diff seconds\n"; 44 66 } 45 # Defragement video seek table 67 # Defragment video seek table 68 $t[0]= time(); 69 print "Defragging: filemarkup\n"; 46 70 if ($dbh->do("ALTER TABLE `filemarkup` ORDER BY filename")) { 47 print "Defragmented: filemarkup\n"; 71 print "Defragmented: filemarkup\n"; 72 $t[1]= time(); 73 my $diff = formatted_time_diff(@t); 74 print "Processing took $diff seconds\n"; 48 75 } 49 76 77 # Format calculated time interval 78 79 sub formatted_time_diff { 80 return sprintf("%.2f", $_[1]-$_[0]) 81 }