2 doc/src/sgml/ref/refresh_materialized_view.sgml
3 PostgreSQL documentation
6 <refentry id=
"sql-refreshmaterializedview">
7 <indexterm zone=
"sql-refreshmaterializedview">
8 <primary>REFRESH MATERIALIZED VIEW
</primary>
12 <refentrytitle>REFRESH MATERIALIZED VIEW
</refentrytitle>
13 <manvolnum>7</manvolnum>
14 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
18 <refname>REFRESH MATERIALIZED VIEW
</refname>
19 <refpurpose>replace the contents of a materialized view
</refpurpose>
24 REFRESH MATERIALIZED VIEW [ CONCURRENTLY ]
<replaceable class=
"parameter">name
</replaceable>
30 <title>Description
</title>
33 <command>REFRESH MATERIALIZED VIEW
</command> completely replaces the
34 contents of a materialized view. To execute this command you must have the
35 <literal>MAINTAIN
</literal>
36 privilege on the materialized view. The old contents are discarded. If
37 <literal>WITH DATA
</literal> is specified (or defaults) the backing query
38 is executed to provide the new data, and the materialized view is left in a
39 scannable state. If
<literal>WITH NO DATA
</literal> is specified no new
40 data is generated and the materialized view is left in an unscannable
44 <literal>CONCURRENTLY
</literal> and
<literal>WITH NO DATA
</literal> may not
45 be specified together.
50 <title>Parameters
</title>
54 <term><literal>CONCURRENTLY
</literal></term>
57 Refresh the materialized view without locking out concurrent selects on
58 the materialized view. Without this option a refresh which affects a
59 lot of rows will tend to use fewer resources and complete more quickly,
60 but could block other connections which are trying to read from the
61 materialized view. This option may be faster in cases where a small
62 number of rows are affected.
65 This option is only allowed if there is at least one
66 <literal>UNIQUE
</literal> index on the materialized view which uses only
67 column names and includes all rows; that is, it must not be an
68 expression index or include a
<literal>WHERE
</literal> clause.
71 This option can only be used when the materialized view is already
75 Even with this option only one
<literal>REFRESH
</literal> at a time may
76 run against any one materialized view.
82 <term><replaceable class=
"parameter">name
</replaceable></term>
85 The name (optionally schema-qualified) of the materialized view to
97 If there is an
<literal>ORDER BY
</literal> clause in the materialized
98 view's defining query, the original contents of the materialized view
99 will be ordered that way; but
<command>REFRESH MATERIALIZED
100 VIEW
</command> does not guarantee to preserve that ordering.
104 While
<command>REFRESH MATERIALIZED VIEW
</command> is running, the
<xref
105 linkend=
"guc-search-path"/> is temporarily changed to
<literal>pg_catalog,
111 <title>Examples
</title>
114 This command will replace the contents of the materialized view called
115 <literal>order_summary
</literal> using the query from the materialized
116 view's definition, and leave it in a scannable state:
118 REFRESH MATERIALIZED VIEW order_summary;
123 This command will free storage associated with the materialized view
124 <literal>annual_statistics_basis
</literal> and leave it in an unscannable
127 REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
128 </programlisting></para>
132 <title>Compatibility
</title>
135 <command>REFRESH MATERIALIZED VIEW
</command> is a
136 <productname>PostgreSQL
</productname> extension.
141 <title>See Also
</title>
143 <simplelist type=
"inline">
144 <member><xref linkend=
"sql-creatematerializedview"/></member>
145 <member><xref linkend=
"sql-altermaterializedview"/></member>
146 <member><xref linkend=
"sql-dropmaterializedview"/></member>