OVH Community, votre nouvel espace communautaire.

Script de mesure de la taille d'une base de données


moissan
24/04/2014, 14h00
aujourd'hui la colonne taille a disparu dans phpmyadmin ... il y a eu un changement : la fenetre qui demande le mot de passe n'est plus la même

pour eviter le hors sujet ici , j'ai posé la question la
http://forum.ovh.com/showthread.php?...724#post606724
et la reponse est dèja arrivé

Gaston_Phone
24/04/2014, 00h14
Citation Envoyé par moissan
donc je pourrait en conclure ... que l'indexation est construite en intallant les data ?
Je le pense aussi.

moissan
24/04/2014, 00h01
merci ... ça me fait decouvir beaucoup depuis quelque jours

je remarque aussi que la taille des dump de base de donné est plus proche de la taille data que de la taille totale data et index

donc je pourrait en conclure que le dump ne contient que les data , que l'indexation est construite en intallant les data ?

Gaston_Phone
23/04/2014, 23h13
Citation Envoyé par moissan
autre question dans le manager ovh je vois : taille 243.489 Mo limite 400 Mo
faut il en conclure que c'est uniquement la taille data qui est compté ?
Tout à fait.
OVH a toujours affirmé qu'il indexait d'office toutes les tables et que l'espace occupé par l'indexation était pris en dehors du quota.

moissan
23/04/2014, 22h56
bonjour , je viens d'essayer ce scrip , mais je ne comprend pas le chiffre en haut a droite
Code:
DATABASE chatelotmod2 Ouverture OK
Base : chatelotmod2 Taille : 735 335 784
Table 	                 Taille data 	      Taille index 	Lignes
mwi_archive 	             16 384 	           49 152 	        31
mwi_category 	             16 384 	          32 768 	        13
...
mwi_user_newtalk 	     16 384 	          32 768 	         0
mwi_user_properties          16 384 	           16 384 	        41
mwi_valid_tag 	             16 384           	             0 	         0
mwi_watchlist 	             16 384 	           16 384 	     182
Totaux : 	        248 886 964 	    118 780 928
en faisant l'addition 248 886 964 + 118 780 928 = 367 667 892 ça correspond a ce que dit phpmyadmin 350,6 Mio

mais que signifie ce Taille : 735 335 784 en haut du tableau ?
en cherchant dans le script c'est $Total ... mais je n'arrive pas a voir d'ou il vient ?

autre question dans le manager ovh je vois : taille 243.489 Mo limite 400 Mo
faut il en conclure que c'est uniquement la taille data qui est compté ?

merci

inculte2provinc
29/11/2011, 14h06
Super ce script Abogil et merci pour le partage

Je suis loin d'être un expert aussi je me permets de poser une question :
Est-il possible de créer une alerte (affichée en front pour un admin ou envoyée par e-mail) quand la taille de la base de données atteint un certain poids ?

Merci pour vos réponse,
Inculte

Tech-Jonathan
23/03/2007, 14h40
Coucou,

Le script fonctionne bien sur une base mysql5 mais sur ma base mysql4 ca affiche des données éronnées.

Abogil
19/03/2007, 20h31
L'as-tu testé et comparé avec les résultats donnés avec le manager V3 ?

J'obtiens moins de 3% d'erreurs entre ma méthode et le manager V3.

Pour moi, je trouve :
- Manager V3 : 31.15 Mo
- Mon script : 30 427 572 Octets

sadkun
19/03/2007, 19h55
Merci pour cette très bonne initiative

Abogil
19/03/2007, 18h23
Bonjour à toutes et à toutes,

J'ai réalisé un petit script, basé sur show table status, qui donne le total de la taille d'une base de données plus pour chaque table :
- La taille des Data,
- La taille de l'index,
- Le nombre de lignes,


Code PHP:



Taille d'une base de données





   
// Paramètres d'entrée à modifier :
   // --------------------------------

   
$DBhost  "mysql5_1";
   
$DBName  "xxxxx";
   
$DBowner "yyyyy";
   
$DBpw    "zzzzz";

   
// DOCUMENTATION
   // -------------

/*   

   // http://dev.mysql.com/doc/refman/5.0/en/show-table-status.html

   0  Name        The name of the table.
   1  Engine        The storage engine for the table. See Chapter 14, Storage Engines and Table Types.
   2  Version        The version number of the table's .frm file.
   3  Row_format    The row storage format (Fixed, Dynamic, Compressed, Redundant, Compact). Starting with MySQL/InnoDB 5.0.3, the format of InnoDB tables is reported as Redundant or Compact. Prior to 5.0.3, InnoDB tables are always in the Redundant format.
   4  Rows        The number of rows. Some storage engines, such as MyISAM, store the exact count. For other storage engines, such as InnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, use SELECT COUNT(*) to obtain an accurate count.
            The Rows value is NULL for tables in the INFORMATION_SCHEMA database.
   5  Avg_row_length    The average row length.
   6  Data_length    The length of the data file.
   7  Max_data_length    The maximum length of the data file. This is the total number of bytes of data that can be stored in the table, given the data pointer size used.
   8  Index_length    The length of the index file.
   9  Data_free        The number of allocated but unused bytes.
   10 Auto_increment    The next AUTO_INCREMENT value.
   11 Create_time    When the table was created.
   12 Update_time    When the data file was last updated. For some storage engines, this value is NULL. For example, InnoDB stores multiple tables in its tablespace and the data file timestamp does not apply.
   13 Check_time    When the table was last checked. Not all storage engines update this time, in which case the value is always NULL.
   14 Collation        The table's character set and collation.
   15 Checksum        The live checksum value (if any).
   16 Create_options    Extra options used with CREATE TABLE.
   17 Comment        The comment used when creating the table (or information as to why MySQL could not access the table information).
*/


   // Ouverture de la base et accès aux tables
   // ----------------------------------------

   
$fh_db=mysql_connect($DBhost$DBowner$DBpw); 
   if ((
$fh_db)) 
      { 
      
// echo "DATABASE  >>$fh_db<< " . $DBName . " Connexion OK 
 ";
      
$sel=mysql_select_db($DBName,$fh_db); 
      if (
$sel)   echo "DATABASE $DBName "  Ouverture OK 
 "
;
      else        echo 
"DATABASE $DBName "  Ouverture  impossible   
 "
      } 
   else
      {
      echo 
"DATABASE $DBName "  Connexion  impossible   
 "
      exit;
      }

   
$Aff_size         "";
   
$Total            0;
   
$Total_data       0;
   
$Total_index      0;
   
$Tab_tables       = array();
   
$result_count_row 0;
   
$count            0;

   
$sql_query "SHOW TABLE STATUS FROM $DBName";
   
$result_query mysql_query($sql_query); 

   if (!isset(
$result_query))  echo 
 ####  " 
mysql_error() . 
 ####  " 
"Requête : \$sql_query=$sql_query 
 
 \n"

   else
      {
      while (
$result_query && $row=mysql_fetch_row($result_query)) 
         {
         
$count $count 1;
         
$Table_liste $row[0];  // Name
         
$row_1       $row[1];  // Engine
         
$row_2       $row[2];  // Version
         
$row_3       $row[3];  // Row_format
         
$row_4       $row[4];  // Rows
         
$row_5       $row[5];  // Avg_row_length

         
$Table $row ['0'];                                // Name
         
$Tab_tables ["$Table"]['Total_Rows'] = $row ['4'];  // Rows
         
$Tab_tables ["$Table"]['Table_Size'] = $row ['6'];  // Data_length
         
$Tab_tables ["$Table"]['Index_Size'] = $row ['8'];  // Index_length
         
$Total $Total $Tab_tables ["$Table"]['Table_Size'] + $Tab_tables ["$Table"]['Index_Size'];
         
$Total       $Total       $Tab_tables ["$Table"]['Table_Size'] + $Tab_tables ["$Table"]['Index_Size'];
         
$Total_data  $Total_data  $Tab_tables ["$Table"]['Table_Size'];
         
$Total_index $Total_index $Tab_tables ["$Table"]['Index_Size'];
         }
      } 


   
// Contenu de chaque table MySQL

 
   
$Tab_col = array();
   
reset ($Tab_tables);
   while(list(
$Table$data) = each($Tab_tables))
      {
      
$count 0;
      
$sql_query_col="SHOW COLUMNS FROM $Table"
      
$result_col=mysql_query($sql_query_col); 
      
$Tableau_colonnes = array();
      while (
$result_col && $row=mysql_fetch_array($result_col)) 
         { 
         
$count    $count 1;
         
$Nom_col  $row[0];
         
$Type_col $row[1];
         
$Tab_col ["$Table"]['Liste_col']["$Nom_col"]['Type_col']= $Type_col;
         }
      
$Tab_col ["$Table"]['Liste_col']['Nb_col']= $count;
      }

   
// Fermeture de la connexion
   
mysql_close($fh_db);                                     


   
// Affichage des tailles des tables MySQL

   
$Total_len strlen($Total);
   if (
$Total_len && $Total_len <= 6)   $Total substr($Total$Total_len ) . " " substr($Total$Total_len 3);
   if (
$Total_len && $Total_len <= 9)   $Total substr($Total$Total_len ) . " " substr($Total$Total_len 3) . " " substr($Total$Total_len 3);

   
$Aff_size .= "
 \n";
   
$Aff_size .= " \n";
   
$Aff_size .= "  \n";
   
$Aff_size .= " 
 Base :  $DBName  Taille :  $Total  
  \n"
;
   
$Aff_size .= "  \n";
   
$Aff_size .= " \n";
   
$Aff_size .=  Table          \n";
   
$Aff_size .=  Taille data    \n";
   
$Aff_size .=  Taille index   \n";
   
$Aff_size .=  Lignes         \n";
   
$Aff_size .= " \n";
   
$Aff_size .= "  \n";


   
// Affichage des tables
   
reset ($Tab_tables);
   while(list(
$Table$data) = each($Tab_tables))
      {
      
$Table_Size $Tab_tables ["$Table"]['Table_Size'];
      
$Table_Size_len strlen($Table_Size);
      if (
$Table_Size_len && $Table_Size_len <= 6)   $Table_Size substr($Table_Size$Table_Size_len ) . " " substr($Table_Size$Table_Size_len 3);
      if (
$Table_Size_len && $Table_Size_len <= 9)   $Table_Size substr($Table_Size$Table_Size_len ) . " " substr($Table_Size$Table_Size_len 3) . " " substr($Table_Size$Table_Size_len 3);

      
$Total_Rows $Tab_tables ["$Table"]['Total_Rows'];
      
$Total_Rows_len strlen($Total_Rows);
      if (
$Total_Rows_len && $Total_Rows_len <= 6)   $Total_Rows substr($Total_Rows$Total_Rows_len ) . " " substr($Total_Rows$Total_Rows_len 3);
      if (
$Total_Rows_len && $Total_Rows_len <= 9)   $Total_Rows substr($Total_Rows$Total_Rows_len ) . " " substr($Total_Rows$Total_Rows_len 3) . " " substr($Total_Rows$Total_Rows_len 3);

      
$Index_Size $Tab_tables ["$Table"]['Index_Size'];
      
$Index_Size_len strlen($Index_Size);
      if (
$Index_Size_len && $Index_Size_len <= 6)   $Index_Size substr($Index_Size$Index_Size_len ) . " " substr($Index_Size$Index_Size_len 3);
      if (
$Index_Size_len && $Index_Size_len <= 9)   $Index_Size substr($Index_Size$Index_Size_len ) . " " substr($Index_Size$Index_Size_len 3) . " " substr($Index_Size$Index_Size_len 3);

      
$Aff_size .= " \n";
      
$Aff_size .= "   " $Table .      " \n";
      
$Aff_size .= "  " $Table_Size " \n";
      
$Aff_size .= "  " $Index_Size " \n";
      
$Aff_size .= "  " $Total_Rows " \n";
      
$Aff_size .= " \n";
      }

   
$Aff_size .= "  \n";

   
$Total_data_len strlen($Total_data);
   if (
$Total_data_len && $Total_data_len <= 6)   $Total_data substr($Total_data$Total_data_len ) . " " substr($Total_data$Total_data_len 3);
   if (
$Total_data_len && $Total_data_len <= 9)   $Total_data substr($Total_data$Total_data_len ) . " " substr($Total_data$Total_data_len 3) . " " substr($Total_data$Total_data_len 3);

   
$Total_index_len strlen($Total_index);
   if (
$Total_index_len && $Total_index_len <= 6)   $Total_index substr($Total_index$Total_index_len ) . " " substr($Total_index$Total_index_len 3);
   if (
$Total_index_len && $Total_index_len <= 9)   $Total_index substr($Total_index$Total_index_len ) . " " substr($Total_index$Total_index_len 3) . " " substr($Total_index$Total_index_len 3);

   
$Aff_size .= " \n";
   
$Aff_size .= "        Totaux :           \n";
   
$Aff_size .= "   " $Total_data    \n";
   
$Aff_size .= "   " $Total_index   \n";
   
$Aff_size .= "                                  \n";
   
$Aff_size .= " \n";

   
$Aff_size .= " \n";
   
$Aff_size .= "
 \n"
;

   
$Aff_size .= "
 \n"
;


   
// Affichage des résultats

   
print $Aff_size;
?>