]> begriffs open source - ai-pg/blob - full-docs/man7/REFRESH_MATERIALIZED_VIEW.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / REFRESH_MATERIALIZED_VIEW.7
1 '\" t
2 .\"     Title: REFRESH MATERIALIZED VIEW
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "REFRESH MATERIALIZED VIEW" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 REFRESH_MATERIALIZED_VIEW \- replace the contents of a materialized view
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] \fIname\fR
36     [ WITH [ NO ] DATA ]
37 .fi
38 .SH "DESCRIPTION"
39 .PP
40 \fBREFRESH MATERIALIZED VIEW\fR
41 completely replaces the contents of a materialized view\&. To execute this command you must have the
42 MAINTAIN
43 privilege on the materialized view\&. The old contents are discarded\&. If
44 WITH DATA
45 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
46 WITH NO DATA
47 is specified no new data is generated and the materialized view is left in an unscannable state\&.
48 .PP
49 CONCURRENTLY
50 and
51 WITH NO DATA
52 may not be specified together\&.
53 .SH "PARAMETERS"
54 .PP
55 CONCURRENTLY
56 .RS 4
57 Refresh 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\&.
58 .sp
59 This option is only allowed if there is at least one
60 UNIQUE
61 index on the materialized view which uses only column names and includes all rows; that is, it must not be an expression index or include a
62 WHERE
63 clause\&.
64 .sp
65 This option can only be used when the materialized view is already populated\&.
66 .sp
67 Even with this option only one
68 REFRESH
69 at a time may run against any one materialized view\&.
70 .RE
71 .PP
72 \fIname\fR
73 .RS 4
74 The name (optionally schema\-qualified) of the materialized view to refresh\&.
75 .RE
76 .SH "NOTES"
77 .PP
78 If there is an
79 ORDER BY
80 clause in the materialized view\*(Aqs defining query, the original contents of the materialized view will be ordered that way; but
81 \fBREFRESH MATERIALIZED VIEW\fR
82 does not guarantee to preserve that ordering\&.
83 .PP
84 While
85 \fBREFRESH MATERIALIZED VIEW\fR
86 is running, the
87 search_path
88 is temporarily changed to
89 pg_catalog, pg_temp\&.
90 .SH "EXAMPLES"
91 .PP
92 This command will replace the contents of the materialized view called
93 order_summary
94 using the query from the materialized view\*(Aqs definition, and leave it in a scannable state:
95 .sp
96 .if n \{\
97 .RS 4
98 .\}
99 .nf
100 REFRESH MATERIALIZED VIEW order_summary;
101 .fi
102 .if n \{\
103 .RE
104 .\}
105 .PP
106 This command will free storage associated with the materialized view
107 annual_statistics_basis
108 and leave it in an unscannable state:
109 .sp
110 .if n \{\
111 .RS 4
112 .\}
113 .nf
114 REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
115 .fi
116 .if n \{\
117 .RE
118 .\}
119 .SH "COMPATIBILITY"
120 .PP
121 \fBREFRESH MATERIALIZED VIEW\fR
122 is a
123 PostgreSQL
124 extension\&.
125 .SH "SEE ALSO"
126 CREATE MATERIALIZED VIEW (\fBCREATE_MATERIALIZED_VIEW\fR(7)), ALTER MATERIALIZED VIEW (\fBALTER_MATERIALIZED_VIEW\fR(7)), DROP MATERIALIZED VIEW (\fBDROP_MATERIALIZED_VIEW\fR(7))