| 1 |
<!-- |
| 2 |
doc/src/sgml/ref/refresh_materialized_view.sgml |
| 3 |
PostgreSQL documentation |
| 4 |
--> |
| 5 |
|
| 6 |
<refentry id="sql-refreshmaterializedview"> |
| 7 |
<indexterm zone="sql-refreshmaterializedview"> |
| 8 |
<primary>REFRESH MATERIALIZED VIEW</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<refmeta> |
| 12 |
<refentrytitle>REFRESH MATERIALIZED VIEW</refentrytitle> |
| 13 |
<manvolnum>7</manvolnum> |
| 14 |
<refmiscinfo>SQL - Language Statements</refmiscinfo> |
| 15 |
</refmeta> |
| 16 |
|
| 17 |
<refnamediv> |
| 18 |
<refname>REFRESH MATERIALIZED VIEW</refname> |
| 19 |
<refpurpose>replace the contents of a materialized view</refpurpose> |
| 20 |
</refnamediv> |
| 21 |
|
| 22 |
<refsynopsisdiv> |
| 23 |
<synopsis> |
| 24 |
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <replaceable class="parameter">name</replaceable> |
| 25 |
[ WITH [ NO ] DATA ] |
| 26 |
</synopsis> |
| 27 |
</refsynopsisdiv> |
| 28 |
|
| 29 |
<refsect1> |
| 30 |
<title>Description</title> |
| 31 |
|
| 32 |
<para> |
| 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 |
| 41 |
state. |
| 42 |
</para> |
| 43 |
<para> |
| 44 |
<literal>CONCURRENTLY</literal> and <literal>WITH NO DATA</literal> may not |
| 45 |
be specified together. |
| 46 |
</para> |
| 47 |
</refsect1> |
| 48 |
|
| 49 |
<refsect1> |
| 50 |
<title>Parameters</title> |
| 51 |
|
| 52 |
<variablelist> |
| 53 |
<varlistentry> |
| 54 |
<term><literal>CONCURRENTLY</literal></term> |
| 55 |
<listitem> |
| 56 |
<para> |
| 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. |
| 63 |
</para> |
| 64 |
<para> |
| 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. |
| 69 |
</para> |
| 70 |
<para> |
| 71 |
This option can only be used when the materialized view is already |
| 72 |
populated. |
| 73 |
</para> |
| 74 |
<para> |
| 75 |
Even with this option only one <literal>REFRESH</literal> at a time may |
| 76 |
run against any one materialized view. |
| 77 |
</para> |
| 78 |
</listitem> |
| 79 |
</varlistentry> |
| 80 |
|
| 81 |
<varlistentry> |
| 82 |
<term><replaceable class="parameter">name</replaceable></term> |
| 83 |
<listitem> |
| 84 |
<para> |
| 85 |
The name (optionally schema-qualified) of the materialized view to |
| 86 |
refresh. |
| 87 |
</para> |
| 88 |
</listitem> |
| 89 |
</varlistentry> |
| 90 |
</variablelist> |
| 91 |
</refsect1> |
| 92 |
|
| 93 |
<refsect1> |
| 94 |
<title>Notes</title> |
| 95 |
|
| 96 |
<para> |
| 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. |
| 101 |
</para> |
| 102 |
|
| 103 |
<para> |
| 104 |
While <command>REFRESH MATERIALIZED VIEW</command> is running, the <xref |
| 105 |
linkend="guc-search-path"/> is temporarily changed to <literal>pg_catalog, |
| 106 |
pg_temp</literal>. |
| 107 |
</para> |
| 108 |
</refsect1> |
| 109 |
|
| 110 |
<refsect1> |
| 111 |
<title>Examples</title> |
| 112 |
|
| 113 |
<para> |
| 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: |
| 117 |
<programlisting> |
| 118 |
REFRESH MATERIALIZED VIEW order_summary; |
| 119 |
</programlisting> |
| 120 |
</para> |
| 121 |
|
| 122 |
<para> |
| 123 |
This command will free storage associated with the materialized view |
| 124 |
<literal>annual_statistics_basis</literal> and leave it in an unscannable |
| 125 |
state: |
| 126 |
<programlisting> |
| 127 |
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA; |
| 128 |
</programlisting></para> |
| 129 |
</refsect1> |
| 130 |
|
| 131 |
<refsect1> |
| 132 |
<title>Compatibility</title> |
| 133 |
|
| 134 |
<para> |
| 135 |
<command>REFRESH MATERIALIZED VIEW</command> is a |
| 136 |
<productname>PostgreSQL</productname> extension. |
| 137 |
</para> |
| 138 |
</refsect1> |
| 139 |
|
| 140 |
<refsect1> |
| 141 |
<title>See Also</title> |
| 142 |
|
| 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> |
| 147 |
</simplelist> |
| 148 |
</refsect1> |
| 149 |
|
| 150 |
</refentry> |