REFRESH_MATERIALIZED_VIEW(7pg15)
π REFRESH_MATERIALIZED_VIEW π
okay bestie, so this is page 7 of the PostgreSQL 15.19 documentation and it's literally all about REFRESH_MATERIALIZED_VIEW β like, one whole manpage, and it's lowkey kind of the moment. pull up a chair π
β¨ NAME β¨
REFRESH_MATERIALIZED_VIEW β replace the contents of a materialized view π¦
β¨ SYNOPSIS β¨
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name
[ WITH [ NO ] DATA ]
that's it. that's the whole vibe. π«Ά
β¨ DESCRIPTION β¨
so REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. no leftovers, no "hmm what was in here before" β old contents? discarded. gone. π
one important thing: to run this command you must be the owner of the materialized view. it's giving main character energy and you need the credentials to match. π
now, the two flavors:
- if
WITH DATAis specified β or if you just don't say anything and it defaults to that β the backing query gets executed to provide the new data, and the materialized view is left in a scannable state. yes ma'am, fully functional, ready to be read πΈ - if
WITH NO DATAis specified, no new data is generated and the materialized view is left in an unscannable state. it's empty, it's resting, it's not giving anything π
real talk:CONCURRENTLYandWITH NO DATAmay not be specified together. periodt. pick one, not both.
β¨ PARAMETERS β¨
CONCURRENTLYβ refresh the materialized view without locking out concurrent selects on the materialized view. π without this option, a refresh that affects a lot of rows will tend to use fewer resources and complete more quickly, but it could block other connections that are trying to read from the materialized view. so it's a trade-off, iykyk. 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 oneUNIQUEindex 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. so if you're out here with a fancy partial index, this flag said no β this option may not be used when the materialized view is not already populated. it has to have been filled at least once, bestie. even with this option, only oneREFRESHat a time may run against any one materialized view. no tag-teaming. one at a time. πnameβ the name (optionally schema-qualified) of the materialized view to refresh. that's your girl π¦
β¨ NOTES β¨
if there's an ORDER BY clause in the materialized view's defining query, the original contents of the materialized view will be ordered that way β cute, right? but heads up: REFRESH MATERIALIZED VIEW does not guarantee to preserve that ordering. so don't come for her if the order shifts. π
β¨ 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;
and this one 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;
see how they're different? obsessed. β¨
β¨ COMPATIBILITY β¨
REFRESH MATERIALIZED VIEW is a PostgreSQL extension. it's not standard SQL, it's our thing. π
β¨ SEE ALSO β¨
CREATE MATERIALIZED VIEW(CREATE_MATERIALIZED_VIEW(7))ALTER MATERIALIZED VIEW(ALTER_MATERIALIZED_VIEW(7))DROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7))
go read those too, the whole family ate π₯
and that's the tea, bestie π this page is straight out of the PostgreSQL 15.19 docs, dated 2026 β go refresh something iconic today ππ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-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