Indenting mysqltuner at 2024-02-06T17:58:52+01:00

This commit is contained in:
Jean-Marie Renouard 2024-02-06 17:58:57 +01:00
parent 30d1d9ecc6
commit dd2ed72642

View file

@ -196,7 +196,7 @@ if ( exists $opt{passenv} && exists $ENV{ $opt{passenv} } ) {
$opt{pass} = $opt{password} if ( $opt{pass} eq 0 and $opt{password} ne 0 ); $opt{pass} = $opt{password} if ( $opt{pass} eq 0 and $opt{password} ne 0 );
if ( $opt{dumpdir} ne '' ) { if ( $opt{dumpdir} ne '' ) {
$opt{dumpdir}= abs_path($opt{dumpdir}); $opt{dumpdir} = abs_path( $opt{dumpdir} );
if ( !-d $opt{dumpdir} ) { if ( !-d $opt{dumpdir} ) {
mkdir $opt{dumpdir} or die "Cannot create directory $opt{dumpdir}: $!"; mkdir $opt{dumpdir} or die "Cannot create directory $opt{dumpdir}: $!";
} }
@ -237,8 +237,9 @@ $opt{structstat} = 0
if ( not defined( $opt{structstat} ) or $opt{nostructstat} == 1 ) if ( not defined( $opt{structstat} ) or $opt{nostructstat} == 1 )
; # Don't print table struct information ; # Don't print table struct information
$opt{myisamstat} = 1 $opt{myisamstat} = 1
if ( not defined( $opt{myisamstat} )); if ( not defined( $opt{myisamstat} ) );
$opt{myisamstat} = 0 if ($opt{nomyisamstat} == 1 ); # Don't print MyISAM table information $opt{myisamstat} = 0
if ( $opt{nomyisamstat} == 1 ); # Don't print MyISAM table information
# for RPM distributions # for RPM distributions
$opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv" $opt{cvefile} = "/usr/share/mysqltuner/vulnerabilities.csv"
@ -814,7 +815,8 @@ sub mysql_setup {
if ( $opt{socket} ne 0 ) { if ( $opt{socket} ne 0 ) {
if ( $opt{port} ne 0 ) { if ( $opt{port} ne 0 ) {
$remotestring = " -S $opt{socket} -P $opt{port}"; $remotestring = " -S $opt{socket} -P $opt{port}";
} else { }
else {
$remotestring = " -S $opt{socket}"; $remotestring = " -S $opt{socket}";
} }
} }
@ -1579,7 +1581,9 @@ sub log_file_recommendations {
$numLi++; $numLi++;
debugprint "$numLi: $logLi" debugprint "$numLi: $logLi"
if $logLi =~ /warning|error/i and $logLi !~ /Logging to/; if $logLi =~ /warning|error/i and $logLi !~ /Logging to/;
$nbErrLog++ if $logLi =~ /error/i and $logLi !~ /(Logging to|\[Warning\].*ERROR_FOR_DIVISION_BY_ZERO)/; $nbErrLog++
if $logLi =~ /error/i
and $logLi !~ /(Logging to|\[Warning\].*ERROR_FOR_DIVISION_BY_ZERO)/;
$nbWarnLog++ if $logLi =~ /warning/i; $nbWarnLog++ if $logLi =~ /warning/i;
push @lastShutdowns, $logLi push @lastShutdowns, $logLi
if $logLi =~ /Shutdown complete/ and $logLi !~ /Innodb/i; if $logLi =~ /Shutdown complete/ and $logLi !~ /Innodb/i;
@ -3179,7 +3183,7 @@ sub calculations {
unless defined $mystat{'Innodb_buffer_pool_reads'}; unless defined $mystat{'Innodb_buffer_pool_reads'};
$mycalc{'pct_read_efficiency'} = percentage( $mycalc{'pct_read_efficiency'} = percentage(
$mystat{'Innodb_buffer_pool_read_requests'}, $mystat{'Innodb_buffer_pool_read_requests'},
( (
$mystat{'Innodb_buffer_pool_read_requests'} + $mystat{'Innodb_buffer_pool_read_requests'} +
$mystat{'Innodb_buffer_pool_reads'} $mystat{'Innodb_buffer_pool_reads'}
) )
@ -3210,11 +3214,12 @@ sub calculations {
$mystat{'Innodb_buffer_pool_pages_total'} $mystat{'Innodb_buffer_pool_pages_total'}
) if defined $mystat{'Innodb_buffer_pool_pages_total'}; ) if defined $mystat{'Innodb_buffer_pool_pages_total'};
$mycalc{'innodb_buffer_alloc_pct'}=select_one( $mycalc{'innodb_buffer_alloc_pct'} = select_one(
"select round( 100* sum(allocated)/( select VARIABLE_VALUE ". "select round( 100* sum(allocated)/( select VARIABLE_VALUE "
"FROM performance_schema.global_variables " . . "FROM performance_schema.global_variables "
"WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)". . "WHERE VARIABLE_NAME='innodb_buffer_pool_size' ) ,2)"
'FROM sys.x\$innodb_buffer_stats_by_table;'); . 'FROM sys.x\$innodb_buffer_stats_by_table;' );
# Binlog Cache # Binlog Cache
if ( $myvar{'log_bin'} ne 'OFF' ) { if ( $myvar{'log_bin'} ne 'OFF' ) {
$mycalc{'pct_binlog_cache'} = percentage( $mycalc{'pct_binlog_cache'} = percentage(
@ -6360,59 +6365,60 @@ sub mysql_innodb {
. ") if possible." ); . ") if possible." );
} }
# select round( 100* sum(allocated)/( select VARIABLE_VALUE # select round( 100* sum(allocated)/( select VARIABLE_VALUE
# FROM performance_schema.global_variables # FROM performance_schema.global_variables
# where VARIABLE_NAME='innodb_buffer_pool_size' ) # where VARIABLE_NAME='innodb_buffer_pool_size' )
# ,2) as "PCT ALLOC/BUFFER POOL" # ,2) as "PCT ALLOC/BUFFER POOL"
#from sys.x$innodb_buffer_stats_by_table; #from sys.x$innodb_buffer_stats_by_table;
if ($mycalc{innodb_buffer_alloc_pct} < 80) { if ( $mycalc{innodb_buffer_alloc_pct} < 80 ) {
badprint "Ratio Buffer Pool allocated / Buffer Pool Size: ". badprint "Ratio Buffer Pool allocated / Buffer Pool Size: "
$mycalc{'innodb_buffer_alloc_pct'} . '%'; . $mycalc{'innodb_buffer_alloc_pct'} . '%';
} else { }
goodprint "Ratio Buffer Pool allocated / Buffer Pool Size: ". else {
$mycalc{'innodb_buffer_alloc_pct'} . '%'; goodprint "Ratio Buffer Pool allocated / Buffer Pool Size: "
. $mycalc{'innodb_buffer_alloc_pct'} . '%';
} }
if ( $mycalc{'innodb_log_size_pct'} < 20 if ( $mycalc{'innodb_log_size_pct'} < 20
or $mycalc{'innodb_log_size_pct'} > 30 ) or $mycalc{'innodb_log_size_pct'} > 30 )
{ {
if ( defined $myvar{'innodb_redo_log_capacity'} ) { if ( defined $myvar{'innodb_redo_log_capacity'} ) {
badprint badprint
"Ratio InnoDB redo log capacity / InnoDB Buffer pool size (" "Ratio InnoDB redo log capacity / InnoDB Buffer pool size ("
. $mycalc{'innodb_log_size_pct'} . "%): " . $mycalc{'innodb_log_size_pct'} . "%): "
. hr_bytes( $myvar{'innodb_redo_log_capacity'} ) . " / " . hr_bytes( $myvar{'innodb_redo_log_capacity'} ) . " / "
. hr_bytes( $myvar{'innodb_buffer_pool_size'} ) . hr_bytes( $myvar{'innodb_buffer_pool_size'} )
. " should be equal to 25%"; . " should be equal to 25%";
push( @adjvars, push( @adjvars,
"innodb_redo_log_capacity should be (=" "innodb_redo_log_capacity should be (="
. hr_bytes_rnd( $myvar{'innodb_buffer_pool_size'} / 4 ) . hr_bytes_rnd( $myvar{'innodb_buffer_pool_size'} / 4 )
. ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size." . ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
); );
push( @generalrec, push( @generalrec,
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time" "Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
); );
} }
else { else {
badprint "Ratio InnoDB log file size / InnoDB Buffer pool size (" badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
. $mycalc{'innodb_log_size_pct'} . "%): " . $mycalc{'innodb_log_size_pct'} . "%): "
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * " . hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
. $myvar{'innodb_log_files_in_group'} . " / " . $myvar{'innodb_log_files_in_group'} . " / "
. hr_bytes( $myvar{'innodb_buffer_pool_size'} ) . hr_bytes( $myvar{'innodb_buffer_pool_size'} )
. " should be equal to 25%"; . " should be equal to 25%";
push( push(
@adjvars, @adjvars,
"innodb_log_file_size should be (=" "innodb_log_file_size should be (="
. hr_bytes_rnd( . hr_bytes_rnd(
$myvar{'innodb_buffer_pool_size'} / $myvar{'innodb_buffer_pool_size'} /
$myvar{'innodb_log_files_in_group'} / 4 $myvar{'innodb_log_files_in_group'} / 4
) )
. ") if possible, so InnoDB total log file size equals 25% of buffer pool size." . ") if possible, so InnoDB total log file size equals 25% of buffer pool size."
); );
push( @generalrec, push( @generalrec,
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time" "Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
); );
} }
if ( mysql_version_le( 5, 6, 2 ) ) { if ( mysql_version_le( 5, 6, 2 ) ) {
push( @generalrec, push( @generalrec,
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB." "For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
); );
@ -6533,7 +6539,8 @@ sub mysql_innodb {
. $mycalc{'pct_read_efficiency'} . "% (" . $mycalc{'pct_read_efficiency'} . "% ("
. $mystat{'Innodb_buffer_pool_read_requests'} . $mystat{'Innodb_buffer_pool_read_requests'}
. " hits / " . " hits / "
. ( $mystat{'Innodb_buffer_pool_reads'} + $mystat{'Innodb_buffer_pool_read_requests'} ) . ( $mystat{'Innodb_buffer_pool_reads'} +
$mystat{'Innodb_buffer_pool_read_requests'} )
. " total)"; . " total)";
} }
else { else {
@ -6541,7 +6548,8 @@ sub mysql_innodb {
. $mycalc{'pct_read_efficiency'} . "% (" . $mycalc{'pct_read_efficiency'} . "% ("
. $mystat{'Innodb_buffer_pool_read_requests'} . $mystat{'Innodb_buffer_pool_read_requests'}
. " hits / " . " hits / "
. ( $mystat{'Innodb_buffer_pool_reads'} + $mystat{'Innodb_buffer_pool_read_requests'} ) . ( $mystat{'Innodb_buffer_pool_reads'} +
$mystat{'Innodb_buffer_pool_read_requests'} )
. " total)"; . " total)";
} }
@ -6557,7 +6565,7 @@ sub mysql_innodb {
. $mystat{'Innodb_log_write_requests'} . $mystat{'Innodb_log_write_requests'}
. " total)"; . " total)";
push( @adjvars, push( @adjvars,
"innodb_log_buffer_size (> " "innodb_log_buffer_size (> "
. hr_bytes_rnd( $myvar{'innodb_log_buffer_size'} ) . hr_bytes_rnd( $myvar{'innodb_log_buffer_size'} )
. ")" ); . ")" );
} }
@ -6709,20 +6717,21 @@ sub mysql_databases {
percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%"; percentage( $totaldbinfo[2], $totaldbinfo[3] ) . "%";
$result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3]; $result{'Databases'}{'All databases'}{'Total Size'} = $totaldbinfo[3];
print "\n" unless ( $opt{'silent'} or $opt{'json'} ); print "\n" unless ( $opt{'silent'} or $opt{'json'} );
my $nbViews=0; my $nbViews = 0;
my $nbTables=0; my $nbTables = 0;
foreach (@dblist) { foreach (@dblist) {
my @dbinfo = split /\s/, my @dbinfo = split /\s/,
select_one( select_one(
"SELECT TABLE_SCHEMA, SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH), SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(DISTINCT ENGINE), COUNT(TABLE_NAME), COUNT(DISTINCT(TABLE_COLLATION)), COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_' GROUP BY TABLE_SCHEMA ORDER BY TABLE_SCHEMA" "SELECT TABLE_SCHEMA, SUM(TABLE_ROWS), SUM(DATA_LENGTH), SUM(INDEX_LENGTH), SUM(DATA_LENGTH+INDEX_LENGTH), COUNT(DISTINCT ENGINE), COUNT(TABLE_NAME), COUNT(DISTINCT(TABLE_COLLATION)), COUNT(DISTINCT(ENGINE)) FROM information_schema.TABLES WHERE TABLE_SCHEMA='$_' GROUP BY TABLE_SCHEMA ORDER BY TABLE_SCHEMA"
); );
next unless defined $dbinfo[0]; next unless defined $dbinfo[0];
infoprint "Database: " . $dbinfo[0] . ""; infoprint "Database: " . $dbinfo[0] . "";
$nbTables=select_one( $nbTables = select_one(
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_'" "SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$_'"
); );
infoprint " +-- TABLE : $nbTables"; infoprint " +-- TABLE : $nbTables";
infoprint " +-- VIEW : " infoprint " +-- VIEW : "
. select_one( . select_one(
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_'" "SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='VIEW' AND TABLE_SCHEMA='$_'"
@ -6778,10 +6787,10 @@ sub mysql_databases {
) . " TABLE(s)"; ) . " TABLE(s)";
} }
if ( $nbTables == 0 ) { if ( $nbTables == 0 ) {
badprint " No table in $dbinfo[0] database"; badprint " No table in $dbinfo[0] database";
next; next;
} }
badprint "Index size is larger than data size for $dbinfo[0] \n" badprint "Index size is larger than data size for $dbinfo[0] \n"
if ( $dbinfo[2] ne 'NULL' ) if ( $dbinfo[2] ne 'NULL' )
and ( $dbinfo[3] ne 'NULL' ) and ( $dbinfo[3] ne 'NULL' )
@ -6792,7 +6801,7 @@ sub mysql_databases {
. " storage engines. Be careful. \n"; . " storage engines. Be careful. \n";
push @generalrec, push @generalrec,
"Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo[0] database ($dbinfo[5] engines detected)"; "Select one storage engine (InnoDB is a good choice) for all tables in $dbinfo[0] database ($dbinfo[5] engines detected)";
} }
$result{'Databases'}{ $dbinfo[0] }{'Rows'} = $dbinfo[1]; $result{'Databases'}{ $dbinfo[0] }{'Rows'} = $dbinfo[1];
$result{'Databases'}{ $dbinfo[0] }{'Tables'} = $dbinfo[6]; $result{'Databases'}{ $dbinfo[0] }{'Tables'} = $dbinfo[6];
$result{'Databases'}{ $dbinfo[0] }{'Collations'} = $dbinfo[7]; $result{'Databases'}{ $dbinfo[0] }{'Collations'} = $dbinfo[7];
@ -7096,12 +7105,13 @@ ENDSQL
infoprint " +-- COMMENT : " . $info[5] if defined $info[5]; infoprint " +-- COMMENT : " . $info[5] if defined $info[5];
$found++; $found++;
} }
my $nbTables=select_one( my $nbTables = select_one(
"SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$dbname'" "SELECT count(*) from information_schema.TABLES WHERE TABLE_TYPE ='BASE TABLE' AND TABLE_SCHEMA='$dbname'"
); );
badprint "No index found for $dbname database" if $found == 0 and $nbTables>1; badprint "No index found for $dbname database"
if $found == 0 and $nbTables > 1;
push @generalrec, "Add indexes on tables from $dbname database" push @generalrec, "Add indexes on tables from $dbname database"
if $found == 0 and $nbTables>1; if $found == 0 and $nbTables > 1;
} }
return return
unless ( defined( $myvar{'performance_schema'} ) unless ( defined( $myvar{'performance_schema'} )