Home Explore Blog Models CI



postgresql

2nd chunk of `doc/src/sgml/ref/refresh_materialized_view.sgml`
3fca281408267338aa0fff072c6c5864c83587e2a92126f50000000100000cf3
 materialized view is left in an unscannable
   state.
  </para>
  <para>
   <literal>CONCURRENTLY</literal> and <literal>WITH NO DATA</literal> may not
   be specified together.
  </para>
 </refsect1>

 <refsect1>
  <title>Parameters</title>

  <variablelist>
   <varlistentry>
    <term><literal>CONCURRENTLY</literal></term>
    <listitem>
     <para>
      Refresh the materialized view without locking out concurrent selects on
      the materialized view.  Without this option a refresh which affects a
      lot of rows will tend to use fewer resources and complete more quickly,
      but could block other connections which are trying to read from the
      materialized view.  This option may be faster in cases where a small
      number of rows are affected.
     </para>
     <para>
      This option is only allowed if there is at least one
      <literal>UNIQUE</literal> index on the materialized view which uses only
      column names and includes all rows;  that is, it must not be an
      expression index or include a <literal>WHERE</literal> clause.
     </para>
     <para>
      This option can only be used when the materialized view is already
      populated.
     </para>
     <para>
      Even with this option only one <literal>REFRESH</literal> at a time may
      run against any one materialized view.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">name</replaceable></term>
    <listitem>
     <para>
      The name (optionally schema-qualified) of the materialized view to
      refresh.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1>
  <title>Notes</title>

  <para>
   If there is an <literal>ORDER BY</literal> clause in the materialized
   view's defining query, the original contents of the materialized view
   will be ordered that way; but <command>REFRESH MATERIALIZED
   VIEW</command> does not guarantee to preserve that ordering.
  </para>

  <para>
   While <command>REFRESH MATERIALIZED VIEW</command> is running, the <xref
   linkend="guc-search-path"/> is temporarily changed to <literal>pg_catalog,
   pg_temp</literal>.
  </para>
 </refsect1>

 <refsect1>
  <title>Examples</title>

  <para>
   This command will replace the contents of the materialized view called
   <literal>order_summary</literal> using the query from the materialized
   view's definition, and leave it in a scannable state:
<programlisting>
REFRESH MATERIALIZED VIEW order_summary;
</programlisting>
  </para>

  <para>
   This command will free storage associated with the materialized view
   <literal>annual_statistics_basis</literal> and leave it in an unscannable
   state:
<programlisting>
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
</programlisting></para>
 </refsect1>

 <refsect1>
  <title>Compatibility</title>

  <para>
   <command>REFRESH MATERIALIZED VIEW</command> is a
   <productname>PostgreSQL</productname> extension.
  </para>
 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-creatematerializedview"/></member>
   <member><xref linkend="sql-altermaterializedview"/></member>
   <member><xref linkend="sql-dropmaterializedview"/></member>
  </simplelist>
 </refsect1>

</refentry>

Title: REFRESH MATERIALIZED VIEW - Parameters, Notes, Examples, and Compatibility
Summary
This section details the parameters for the REFRESH MATERIALIZED VIEW command, including CONCURRENTLY (allowing refreshes without blocking concurrent selects under certain index conditions) and the materialized view's name. It notes that REFRESH MATERIALIZED VIEW does not guarantee to preserve the ORDER BY clause of the defining query. It provides examples of refreshing with and without data. Finally, it states that the command is a PostgreSQL extension and lists related commands like CREATE, ALTER, and DROP MATERIALIZED VIEW.