REFRESH_MATERIALIZED_VIEW(7pg14)
π REFRESH MATERIALIZED VIEW β the glow-up command
okay bestie, so this is the REFRESH_MATERIALIZED_VIEW(7) page from the PostgreSQL 14.24 documentation, and it's literally about giving your materialized view a whole new look without losing the plot π
β¨ NAME β¨
REFRESH_MATERIALIZED_VIEW β replace the contents of a materialized view. that's it, that's the whole vibe. out with the old, in with the new π¦
π«Ά SYNOPSIS π«Ά
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name
[ WITH [ NO ] DATA ]
not me putting the exact syntax in a code block so you can't mess it up π copy it character for character, bestie. slay responsibly.
πΈ DESCRIPTION πΈ
REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. like a full closet clean-out, no survivors, the old contents are discarded.
to even run this command you gotta be the owner of the materialized view β no sneaking into someone else's wardrobe, periodt π
so here's the tea on the data part:
- if
WITH DATAis specified (or it just defaults, because of course it does), the backing query gets executed to provide the new data, and the materialized view is left in a scannable state β¨ - if
WITH NO DATAis specified, no new data is generated and the materialized view is left in an unscannable state π
π¨ important vibe check:CONCURRENTLYandWITH NO DATAmay not be specified together. they simply cannot coexist, it's giving incompatible star signs.
π PARAMETERS π
CONCURRENTLYβ refresh the materialized view without locking out concurrent selects on it. iconic behavior, honestly. 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 π. 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 UNIQUE index on the materialized view which uses only column names and includes all rows β that is, it must not be an expression index, and it must not include a WHERE clause. no shortcuts, no loopholes, the index has to be legit π
this option may not be used when the materialized view is not already populated. not me showing up uninvited to a party that hasn't started yet.
even with this option, only one REFRESH at a time may run against any one materialized view. one at a time, bestie, we're not doing chaos here π§
nameβ the name (optionally schema-qualified!) of the materialized view you wanna refresh. yes, you can be specific about where it lives, and honestly, respect.
β 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 likeβ¦ it might look cute and sorted, but do not come for it later if it doesn't. that's not a promise, that's a vibe π¦
π 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;
see how the second one is basically a storage-clearing era? iconic. she's empty, she's free, she's unscannable πβ¨
π COMPATIBILITY π
REFRESH MATERIALIZED VIEW is a PostgreSQL extension. not a standard SQL thing, it's our thing, iykyk π
π SEE ALSO π
CREATE MATERIALIZED VIEW(CREATE_MATERIALIZED_VIEW(7)) β where the materialized view era beginsALTER MATERIALIZED VIEW(ALTER_MATERIALIZED_VIEW(7)) β for when you need a little changeDROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7)) β for when it's time to say goodbye π
and that's the whole page, bestie π«Ά this was PostgreSQL 14.24, dated 2026. go forth and refresh your views, literally and emotionally π πΈ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql14 14.24-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