1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>REFRESH MATERIALIZED VIEW</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-reassign-owned.html" title="REASSIGN OWNED" /><link rel="next" href="sql-reindex.html" title="REINDEX" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">REFRESH MATERIALIZED VIEW</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-reassign-owned.html" title="REASSIGN OWNED">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-reindex.html" title="REINDEX">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-REFRESHMATERIALIZEDVIEW"><div class="titlepage"></div><a id="id-1.9.3.162.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">REFRESH MATERIALIZED VIEW</span></h2><p>REFRESH MATERIALIZED VIEW — replace the contents of a materialized view</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
3 REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <em class="replaceable"><code>name</code></em>
5 </pre></div><div class="refsect1" id="id-1.9.3.162.5"><h2>Description</h2><p>
6 <code class="command">REFRESH MATERIALIZED VIEW</code> completely replaces the
7 contents of a materialized view. To execute this command you must have the
8 <code class="literal">MAINTAIN</code>
9 privilege on the materialized view. The old contents are discarded. If
10 <code class="literal">WITH DATA</code> is specified (or defaults) the backing query
11 is executed to provide the new data, and the materialized view is left in a
12 scannable state. If <code class="literal">WITH NO DATA</code> is specified no new
13 data is generated and the materialized view is left in an unscannable
16 <code class="literal">CONCURRENTLY</code> and <code class="literal">WITH NO DATA</code> may not
17 be specified together.
18 </p></div><div class="refsect1" id="id-1.9.3.162.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">CONCURRENTLY</code></span></dt><dd><p>
19 Refresh the materialized view without locking out concurrent selects on
20 the materialized view. Without this option a refresh which affects a
21 lot of rows will tend to use fewer resources and complete more quickly,
22 but could block other connections which are trying to read from the
23 materialized view. This option may be faster in cases where a small
24 number of rows are affected.
26 This option is only allowed if there is at least one
27 <code class="literal">UNIQUE</code> index on the materialized view which uses only
28 column names and includes all rows; that is, it must not be an
29 expression index or include a <code class="literal">WHERE</code> clause.
31 This option can only be used when the materialized view is already
34 Even with this option only one <code class="literal">REFRESH</code> at a time may
35 run against any one materialized view.
36 </p></dd><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
37 The name (optionally schema-qualified) of the materialized view to
39 </p></dd></dl></div></div><div class="refsect1" id="id-1.9.3.162.7"><h2>Notes</h2><p>
40 If there is an <code class="literal">ORDER BY</code> clause in the materialized
41 view's defining query, the original contents of the materialized view
42 will be ordered that way; but <code class="command">REFRESH MATERIALIZED
43 VIEW</code> does not guarantee to preserve that ordering.
45 While <code class="command">REFRESH MATERIALIZED VIEW</code> is running, the <a class="xref" href="runtime-config-client.html#GUC-SEARCH-PATH">search_path</a> is temporarily changed to <code class="literal">pg_catalog,
47 </p></div><div class="refsect1" id="id-1.9.3.162.8"><h2>Examples</h2><p>
48 This command will replace the contents of the materialized view called
49 <code class="literal">order_summary</code> using the query from the materialized
50 view's definition, and leave it in a scannable state:
51 </p><pre class="programlisting">
52 REFRESH MATERIALIZED VIEW order_summary;
55 This command will free storage associated with the materialized view
56 <code class="literal">annual_statistics_basis</code> and leave it in an unscannable
58 </p><pre class="programlisting">
59 REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
60 </pre></div><div class="refsect1" id="id-1.9.3.162.9"><h2>Compatibility</h2><p>
61 <code class="command">REFRESH MATERIALIZED VIEW</code> is a
62 <span class="productname">PostgreSQL</span> extension.
63 </p></div><div class="refsect1" id="id-1.9.3.162.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-creatematerializedview.html" title="CREATE MATERIALIZED VIEW"><span class="refentrytitle">CREATE MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-altermaterializedview.html" title="ALTER MATERIALIZED VIEW"><span class="refentrytitle">ALTER MATERIALIZED VIEW</span></a>, <a class="xref" href="sql-dropmaterializedview.html" title="DROP MATERIALIZED VIEW"><span class="refentrytitle">DROP MATERIALIZED VIEW</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-reassign-owned.html" title="REASSIGN OWNED">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-reindex.html" title="REINDEX">Next</a></td></tr><tr><td width="40%" align="left" valign="top">REASSIGN OWNED </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> REINDEX</td></tr></table></div></body></html>