2013-03-04 01:23:31 +01:00
|
|
|
<!--
|
|
|
|
doc/src/sgml/ref/refresh_materialized_view.sgml
|
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
2017-10-20 03:16:39 +02:00
|
|
|
<refentry id="sql-refreshmaterializedview">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="sql-refreshmaterializedview">
|
|
|
|
<primary>REFRESH MATERIALIZED VIEW</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2013-03-04 01:23:31 +01:00
|
|
|
<refmeta>
|
|
|
|
<refentrytitle>REFRESH MATERIALIZED VIEW</refentrytitle>
|
|
|
|
<manvolnum>7</manvolnum>
|
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>REFRESH MATERIALIZED VIEW</refname>
|
|
|
|
<refpurpose>replace the contents of a materialized view</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<synopsis>
|
2017-10-09 04:00:57 +02:00
|
|
|
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <replaceable class="parameter">name</replaceable>
|
2013-03-04 01:23:31 +01:00
|
|
|
[ WITH [ NO ] DATA ]
|
|
|
|
</synopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>REFRESH MATERIALIZED VIEW</command> completely replaces the
|
2024-03-13 20:49:26 +01:00
|
|
|
contents of a materialized view. To execute this command you must have the
|
|
|
|
<literal>MAINTAIN</literal>
|
|
|
|
privilege on the materialized view. The old contents are discarded. If
|
2013-03-04 01:23:31 +01:00
|
|
|
<literal>WITH DATA</literal> is specified (or defaults) the backing query
|
|
|
|
is executed to provide the new data, and the materialized view is left in a
|
|
|
|
scannable state. If <literal>WITH NO DATA</literal> is specified no new
|
|
|
|
data is generated and the materialized view is left in an unscannable
|
|
|
|
state.
|
|
|
|
</para>
|
2013-07-16 19:55:44 +02:00
|
|
|
<para>
|
|
|
|
<literal>CONCURRENTLY</literal> and <literal>WITH NO DATA</literal> may not
|
|
|
|
be specified together.
|
|
|
|
</para>
|
2013-03-04 01:23:31 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
2013-07-16 19:55:44 +02:00
|
|
|
<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
|
2019-10-24 02:29:02 +02:00
|
|
|
column names and includes all rows; that is, it must not be an
|
|
|
|
expression index or include a <literal>WHERE</literal> clause.
|
2013-07-16 19:55:44 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2023-11-22 22:40:10 +01:00
|
|
|
This option can only be used when the materialized view is already
|
2013-07-16 19:55:44 +02:00
|
|
|
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>
|
|
|
|
|
2013-03-04 01:23:31 +01:00
|
|
|
<varlistentry>
|
2017-10-09 04:00:57 +02:00
|
|
|
<term><replaceable class="parameter">name</replaceable></term>
|
2013-03-04 01:23:31 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The name (optionally schema-qualified) of the materialized view to
|
|
|
|
refresh.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
|
|
|
<para>
|
2021-11-29 18:13:12 +01:00
|
|
|
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.
|
2013-03-04 01:23:31 +01:00
|
|
|
</para>
|
Fix search_path to a safe value during maintenance operations.
While executing maintenance operations (ANALYZE, CLUSTER, REFRESH
MATERIALIZED VIEW, REINDEX, or VACUUM), set search_path to
'pg_catalog, pg_temp' to prevent inconsistent behavior.
Functions that are used for functional indexes, in index expressions,
or in materialized views and depend on a different search path must be
declared with CREATE FUNCTION ... SET search_path='...'.
This change was previously committed as 05e1737351, then reverted in
commit 2fcc7ee7af because it was too late in the cycle.
Preparation for the MAINTAIN privilege, which was previously reverted
due to search_path manipulation hazards.
Discussion: https://postgr.es/m/d4ccaf3658cb3c281ec88c851a09733cd9482f22.camel@j-davis.com
Discussion: https://postgr.es/m/E1q7j7Y-000z1H-Hr%40gemulon.postgresql.org
Discussion: https://postgr.es/m/e44327179e5c9015c8dda67351c04da552066017.camel%40j-davis.com
Reviewed-by: Greg Stark, Nathan Bossart, Noah Misch
2024-03-05 02:31:38 +01:00
|
|
|
|
|
|
|
<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>
|
2013-03-04 01:23:31 +01:00
|
|
|
</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;
|
2013-06-02 04:03:02 +02:00
|
|
|
</programlisting></para>
|
2013-03-04 01:23:31 +01:00
|
|
|
</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">
|
2017-11-23 15:39:47 +01:00
|
|
|
<member><xref linkend="sql-creatematerializedview"/></member>
|
|
|
|
<member><xref linkend="sql-altermaterializedview"/></member>
|
|
|
|
<member><xref linkend="sql-dropmaterializedview"/></member>
|
2013-03-04 01:23:31 +01:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|