REFRESH_MATERIALIZED_VIEW(7pg16)
π REFRESH_MATERIALIZED_VIEW(7) π
PostgreSQL 16.15 Documentation β bestie, this is the glow-up page for REFRESH MATERIALIZED_VIEW β¨
πΈ NAME πΈ
REFRESH_MATERIALIZED_VIEW β replace the contents of a materialized view
π SYNOPSIS π
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name
[ WITH [ NO ] DATA ]
π¦ DESCRIPTION π¦
Okay so REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. To execute this command you must be the owner of the materialized view, fr fr. 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.
Important bestie alert:CONCURRENTLYandWITH NO DATAmay not be specified together. Periodt.
β¨ PARAMETERS β¨
CONCURRENTLYβ refresh the materialized view without locking out concurrent selects on the materialized view. Hereβs the tea:- 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 may not be used when the materialized view is not already populated.
- Even with this option, only one
REFRESHat a time may run against any one materialized view.
nameβ the 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. So donβt come for the ordering, okay? π
π 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. Thatβs it, thatβs the whole vibe.
π«Ά SEE ALSO π«Ά
CREATE MATERIALIZED VIEW(CREATE_MATERIALIZED_VIEW(7))ALTER MATERIALIZED VIEW(ALTER_MATERIALIZED_VIEW(7))DROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7))
Later, bestie π β¨ This iconic little page is from PostgreSQL 16.15, dated 2026. Now go refresh something and slay responsibly ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms