Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/pgstattuple.sgml`
63ede2828a8b4cc2205e2acd202d19c65fbec814234d25100000000100000ced
 of bitmap pages</entry>
       </row>

       <row>
        <entry><structfield>unused_pages</structfield></entry>
        <entry><type>bigint</type></entry>
        <entry>Number of unused pages</entry>
       </row>

       <row>
        <entry><structfield>live_items</structfield></entry>
        <entry><type>bigint</type></entry>
        <entry>Number of live tuples</entry>
       </row>

       <row>
        <entry><structfield>dead_tuples</structfield></entry>
        <entry><type>bigint</type></entry>
        <entry>Number of dead tuples</entry>
       </row>

       <row>
        <entry><structfield>free_percent</structfield></entry>
        <entry><type>float</type></entry>
        <entry>Percentage of free space</entry>
       </row>

      </tbody>
     </tgroup>
    </informaltable>
    </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <indexterm>
      <primary>pg_relpages</primary>
     </indexterm>
     <function>pg_relpages(regclass) returns bigint</function>
    </term>

    <listitem>
     <para>
      <function>pg_relpages</function> returns the number of pages in the
      relation.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>pg_relpages(text) returns bigint</function>
    </term>

    <listitem>
     <para>
      This is the same as <function>pg_relpages(regclass)</function>, except
      that the target relation is specified as TEXT. This function is kept
      because of backward-compatibility so far, and will be deprecated in
      some future release.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <indexterm>
      <primary>pgstattuple_approx</primary>
     </indexterm>
     <function>pgstattuple_approx(regclass) returns record</function>
    </term>

    <listitem>
     <para>
      <function>pgstattuple_approx</function> is a faster alternative to
      <function>pgstattuple</function> that returns approximate results.
      The argument is the target relation's name or OID.
      For example:
<programlisting>
test=&gt; SELECT * FROM pgstattuple_approx('pg_catalog.pg_proc'::regclass);
-[ RECORD 1 ]--------+-------
table_len            | 573440
scanned_percent      | 2
approx_tuple_count   | 2740
approx_tuple_len     | 561210
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

Title: pg_relpages and pgstattuple_approx Functions: Relation Size and Approximate Tuple Statistics
Summary
The pg_relpages function returns the number of pages in a relation, accepting either a regclass or text input for the relation. The pgstattuple_approx function provides an approximate alternative to pgstattuple, returning estimated statistics about live tuples and free space, while providing exact counts for dead tuples. It avoids full-table scans by using visibility map and free space map to estimate live tuple statistics and free space. The output columns are described in the documentation.