REFRESH MATERIALIZED VIEW
replace the contents of a materialized view
English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- anchor
- SQL-REFRESHMATERIALIZEDVIEW
- file
- sql-refreshmaterializedview.html
- lang
- en
- name
- REFRESH MATERIALIZED VIEW
- purpose
- replace the contents of a materialized view
- purpose zh
- 替换物化视图的内容
- sections same as
- Unknown
- slug
- 18
- synopsis html
- REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <em class="replaceable"><code>name</code></em> [ WITH [ NO ] DATA ]
- synopsis text
- REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name [ WITH [ NO ] DATA ]
Syntax
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name
[ WITH [ NO ] DATA ]Syntax diagrams
Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.
Definition PG 18
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name [ WITH [ NO ] DATA ]
Description
REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. To execute this command you must have the MAINTAIN privilege on the materialized view. The old contents are discarded. If WITH DATA 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 WITH NO DATA is specified no new data is generated and the materialized view is left in an unscannable state.
CONCURRENTLY and WITH NO DATA may not be specified together.
Parameters
CONCURRENTLYRefresh 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.
This option is only allowed if there is at least one
UNIQUEindex on the materialized view which uses only column names and includes all rows; that is, it must not be an expression index or include aWHEREclause.This option can only be used when the materialized view is already populated.
Even with this option only one
REFRESHat a time may run against any one materialized view.nameThe name (optionally schema-qualified) of the materialized view to refresh.
Notes
If there is an ORDER BY clause in the materialized view's defining query, the original contents of the materialized view will be ordered that way; but REFRESH MATERIALIZED VIEW does not guarantee to preserve that ordering.
While REFRESH MATERIALIZED VIEW is running, the search_path is temporarily changed to pg_catalog, pg_temp.
Examples
This command will replace the contents of the materialized view called order_summary using the query from the materialized view's definition, and leave it in a scannable state:
REFRESH MATERIALIZED VIEW order_summary;
This command will free storage associated with the materialized view annual_statistics_basis and leave it in an unscannable state:
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
Compatibility
REFRESH MATERIALIZED VIEW is a PostgreSQL extension.
See Also
CREATE MATERIALIZED VIEW, ALTER MATERIALIZED VIEW, DROP MATERIALIZED VIEWCompare versions
Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · wiki-repair-20261023:1da2c1ff25d92d84bc6ec76ca11530e8cda5fecaa7096527492642fb3f707841
Text language: en · wiki-repair-20261023:1da2c1ff25d92d84bc6ec76ca11530e8cda5fecaa7096527492642fb3f707841