Home Explore Blog CI



postgresql

6th chunk of `doc/src/sgml/pgstattuple.sgml`
34a07c28b8f08aaf708229060215712d276982835561e65f0000000100000870

approx_tuple_percent | 97.87
dead_tuple_count     | 0
dead_tuple_len       | 0
dead_tuple_percent   | 0
approx_free_space    | 11996
approx_free_percent  | 2.09
</programlisting>
      The output columns are described in <xref linkend="pgstatapprox-columns"/>.
     </para>

     <para>
      Whereas <function>pgstattuple</function> always performs a
      full-table scan and returns an exact count of live and dead tuples
      (and their sizes) and free space, <function>pgstattuple_approx</function>
      tries to avoid the full-table scan and returns exact dead tuple
      statistics along with an approximation of the number and
      size of live tuples and free space.
     </para>

     <para>
      It does this by skipping pages that have only visible tuples
      according to the visibility map (if a page has the corresponding VM
      bit set, then it is assumed to contain no dead tuples). For such
      pages, it derives the free space value from the free space map, and
      assumes that the rest of the space on the page is taken up by live
      tuples.
     </para>

     <para>
      For pages that cannot be skipped, it scans each tuple, recording its
      presence and size in the appropriate counters, and adding up the
      free space on the page. At the end, it estimates the total number of
      live tuples based on the number of pages and tuples scanned (in the
      same way that VACUUM estimates pg_class.reltuples).
     </para>

     <table id="pgstatapprox-columns">
      <title><function>pgstattuple_approx</function> Output Columns</title>
      <tgroup cols="3">
       <thead>
        <row>
         <entry>Column</entry>
         <entry>Type</entry>
         <entry>Description</entry>
        </row>
       </thead>

       <tbody>
        <row>
         <entry><structfield>table_len</structfield></entry>
         <entry><type>bigint</type></entry>
         <entry>Physical relation length in bytes (exact)</entry>
        </row>
        <row>
         <entry><structfield>scanned_percent</structfield></entry>
         <entry><type>float8</type></entry>
         <entry>Percentage of table scanned</entry>

Title: pgstattuple_approx Function Details: Operation and Output Columns
Summary
The pgstattuple_approx function estimates live tuple and free space statistics without performing a full-table scan. It skips pages with only visible tuples, using the visibility map and free space map to derive free space. For other pages, it scans each tuple and estimates the total number of live tuples. The function's output columns, including table_len, scanned_percent, approx_tuple_count, approx_tuple_len, approx_tuple_percent, dead_tuple_count, dead_tuple_len, dead_tuple_percent, approx_free_space, and approx_free_percent, are detailed with their types and descriptions.