<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="myisamchk-memory">
      </a>
      6.6.4.6 myisamchk Memory Usage
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045306582864">
  </a>
  <p>
   Memory allocation is important when you run
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   .
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   uses
        no more memory than its memory-related variables are set to. If
        you are going to use
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   on very large
        tables, you should first decide how much memory you want it to
        use. The default is to use only about 3MB to perform repairs. By
        using larger values, you can get
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   to
        operate faster. For example, if you have more than 512MB RAM
        available, you could use options such as these (in addition to
        any other options you might specify):
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa91812956"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-terminal">myisamchk <span class="token constant">--myisam_sort_buffer_size</span><span class="token attr-value"><span class="token punctuation">=</span>256M</span> \
           <span class="token constant">--key_buffer_size</span><span class="token attr-value"><span class="token punctuation">=</span>512M</span> \
           <span class="token constant">--read_buffer_size</span><span class="token attr-value"><span class="token punctuation">=</span>64M</span> \
           <span class="token constant">--write_buffer_size</span><span class="token attr-value"><span class="token punctuation">=</span>64M</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span></code></pre>
  </div>
  <p>
   Using
   <code class="option">
    --myisam_sort_buffer_size=16M
   </code>
   is probably
        enough for most cases.
  </p>
  <p>
   Be aware that
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   uses temporary files
        in
   <code class="literal">
    TMPDIR
   </code>
   . If
   <code class="literal">
    TMPDIR
   </code>
   points to a memory file system, out of memory errors can easily
        occur. If this happens, run
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   with
        the
   <a class="link" href="myisamchk-repair-options.html#option_myisamchk_tmpdir">
    <code class="option">
     --tmpdir=
     <em class="replaceable">
      <code>
       dir_name
      </code>
     </em>
    </code>
   </a>
   option to specify a directory located on a file system that has
        more space.
  </p>
  <p>
   When performing repair operations,
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   also needs a lot of disk space:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Twice the size of the data file (the original file and a
            copy). This space is not needed if you do a repair with
      <a class="link" href="myisamchk-repair-options.html#option_myisamchk_quick">
       <code class="option">
        --quick
       </code>
      </a>
      ; in this case,
            only the index file is re-created.
      <span class="emphasis">
       <em>
        This space must
            be available on the same file system as the original data
            file
       </em>
      </span>
      , as the copy is created in the same
            directory as the original.
     </p>
    </li>
    <li class="listitem">
     <p>
      Space for the new index file that replaces the old one. The
            old index file is truncated at the start of the repair
            operation, so you usually ignore this space. This space must
            be available on the same file system as the original data
            file.
     </p>
    </li>
    <li class="listitem">
     <p>
      When using
      <a class="link" href="myisamchk-repair-options.html#option_myisamchk_recover">
       <code class="option">
        --recover
       </code>
      </a>
      or
      <a class="link" href="myisamchk-repair-options.html#option_myisamchk_sort-recover">
       <code class="option">
        --sort-recover
       </code>
      </a>
      (but not
            when using
      <a class="link" href="myisamchk-repair-options.html#option_myisamchk_safe-recover">
       <code class="option">
        --safe-recover
       </code>
      </a>
      ), you need
            space on disk for sorting. This space is allocated in the
            temporary directory (specified by
      <code class="literal">
       TMPDIR
      </code>
      or
      <a class="link" href="myisamchk-repair-options.html#option_myisamchk_tmpdir">
       <code class="option">
        --tmpdir=
        <em class="replaceable">
         <code>
          dir_name
         </code>
        </em>
       </code>
      </a>
      ).
            The following formula yields the amount of space required:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-clike"><div class="docs-select-all right" id="sa34159575"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-clike"><span class="token punctuation">(</span><em class="replaceable">largest_key</em> <span class="token operator">+</span> <em class="replaceable">row_pointer_length</em><span class="token punctuation">)</span> <span class="token operator">*</span> <em class="replaceable">number_of_rows</em> <span class="token operator">*</span> <span class="token number">2</span></code></pre>
     </div>
     <p>
      You can check the length of the keys and the
      <em class="replaceable">
       <code>
        row_pointer_length
       </code>
      </em>
      with
      <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
       <span class="command">
        <strong>
         myisamchk -dv
         <em class="replaceable">
          <code>
           tbl_name
          </code>
         </em>
        </strong>
       </span>
      </a>
      (see
      <a class="xref" href="myisamchk-table-info.html" title="6.6.4.5 Obtaining Table Information with myisamchk">
       Section 6.6.4.5, “Obtaining Table Information with myisamchk”
      </a>
      ). The
      <em class="replaceable">
       <code>
        row_pointer_length
       </code>
      </em>
      and
      <em class="replaceable">
       <code>
        number_of_rows
       </code>
      </em>
      values are the
      <code class="literal">
       Datafile pointer
      </code>
      and
      <code class="literal">
       Data
            records
      </code>
      values in the table description. To
            determine the
      <em class="replaceable">
       <code>
        largest_key
       </code>
      </em>
      value,
            check the
      <code class="literal">
       Key
      </code>
      lines in the table
            description. The
      <code class="literal">
       Len
      </code>
      column indicates the
            number of bytes for each key part. For a multiple-column
            index, the key size is the sum of the
      <code class="literal">
       Len
      </code>
      values for all key parts.
     </p>
    </li>
   </ul>
  </div>
  <p>
   If you have a problem with disk space during repair, you can try
   <a class="link" href="myisamchk-repair-options.html#option_myisamchk_safe-recover">
    <code class="option">
     --safe-recover
    </code>
   </a>
   instead of
   <a class="link" href="myisamchk-repair-options.html#option_myisamchk_recover">
    <code class="option">
     --recover
    </code>
   </a>
   .
  </p>
 </div>
 <br/>
</div>
