3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER INDEX" "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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_INDEX \- change the definition of an index
35 ALTER INDEX [ IF EXISTS ] \fIname\fR RENAME TO \fInew_name\fR
36 ALTER INDEX [ IF EXISTS ] \fIname\fR SET TABLESPACE \fItablespace_name\fR
37 ALTER INDEX \fIname\fR ATTACH PARTITION \fIindex_name\fR
38 ALTER INDEX \fIname\fR [ NO ] DEPENDS ON EXTENSION \fIextension_name\fR
39 ALTER INDEX [ IF EXISTS ] \fIname\fR SET ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] )
40 ALTER INDEX [ IF EXISTS ] \fIname\fR RESET ( \fIstorage_parameter\fR [, \&.\&.\&. ] )
41 ALTER INDEX [ IF EXISTS ] \fIname\fR ALTER [ COLUMN ] \fIcolumn_number\fR
42 SET STATISTICS \fIinteger\fR
43 ALTER INDEX ALL IN TABLESPACE \fIname\fR [ OWNED BY \fIrole_name\fR [, \&.\&.\&. ] ]
44 SET TABLESPACE \fInew_tablespace\fR [ NOWAIT ]
49 changes the definition of an existing index\&. There are several subforms described below\&. Note that the lock level required may differ for each subform\&. An
51 lock is held unless explicitly noted\&. When multiple subcommands are listed, the lock held will be the strictest one required from any subcommand\&.
57 form changes the name of the index\&. If the index is associated with a table constraint (either
60 EXCLUDE), the constraint is renamed as well\&. There is no effect on the stored data\&.
62 Renaming an index acquires a
63 SHARE UPDATE EXCLUSIVE
69 This form changes the index\*(Aqs tablespace to the specified tablespace and moves the data file(s) associated with the index to the new tablespace\&. To change the tablespace of an index, you must own the index and have
71 privilege on the new tablespace\&. All indexes in the current database in a tablespace can be moved by using the
73 form, which will lock all indexes to be moved and then move each one\&. This form also supports
74 OWNED BY, which will only move indexes owned by the roles specified\&. If the
76 option is specified then the command will fail if it is unable to acquire all of the locks required immediately\&. Note that system catalogs will not be moved by this command, use
80 invocations instead if desired\&. See also
81 \fBCREATE TABLESPACE\fR\&.
84 ATTACH PARTITION \fIindex_name\fR
86 Causes the named index (possibly schema\-qualified) to become attached to the altered index\&. The named index must be on a partition of the table containing the index being altered, and have an equivalent definition\&. An attached index cannot be dropped by itself, and will automatically be dropped if its parent index is dropped\&.
89 DEPENDS ON EXTENSION \fIextension_name\fR
91 NO DEPENDS ON EXTENSION \fIextension_name\fR
93 This form marks the index as dependent on the extension, or no longer dependent on that extension if
95 is specified\&. An index that\*(Aqs marked as dependent on an extension is automatically dropped when the extension is dropped\&.
98 SET ( \fIstorage_parameter\fR [= \fIvalue\fR] [, \&.\&.\&. ] )
100 This form changes one or more index\-method\-specific storage parameters for the index\&. See
102 for details on the available parameters\&. Note that the index contents will not be modified immediately by this command; depending on the parameter you might need to rebuild the index with
104 to get the desired effects\&.
107 RESET ( \fIstorage_parameter\fR [, \&.\&.\&. ] )
109 This form resets one or more index\-method\-specific storage parameters to their defaults\&. As with
112 might be needed to update the index entirely\&.
115 ALTER [ COLUMN ] \fIcolumn_number\fR SET STATISTICS \fIinteger\fR
117 This form sets the per\-column statistics\-gathering target for subsequent
119 operations, though can be used only on index columns that are defined as an expression\&. Since expressions lack a unique name, we refer to them using the ordinal number of the index column\&. The target can be set in the range 0 to 10000; alternatively, set it to \-1 to revert to using the system default statistics target (default_statistics_target)\&. For more information on the use of statistics by the
121 query planner, refer to
128 Do not throw an error if the index does not exist\&. A notice is issued in this case\&.
133 The ordinal number refers to the ordinal (left\-to\-right) position of the index column\&.
138 The name (possibly schema\-qualified) of an existing index to alter\&.
143 The new name for the index\&.
146 \fItablespace_name\fR
148 The tablespace to which the index will be moved\&.
153 The name of the extension that the index is to depend on\&.
156 \fIstorage_parameter\fR
158 The name of an index\-method\-specific storage parameter\&.
163 The new value for an index\-method\-specific storage parameter\&. This might be a number or a word depending on the parameter\&.
167 These operations are also possible using
170 is in fact just an alias for the forms of
172 that apply to indexes\&.
174 There was formerly an
175 \fBALTER INDEX OWNER\fR
176 variant, but this is now ignored (with a warning)\&. An index cannot have an owner different from its table\*(Aqs owner\&. Changing the table\*(Aqs owner automatically changes the index as well\&.
178 Changing any part of a system catalog index is not permitted\&.
181 To rename an existing index:
187 ALTER INDEX distributors RENAME TO suppliers;
193 To move an index to a different tablespace:
199 ALTER INDEX distributors SET TABLESPACE fasttablespace;
205 To change an index\*(Aqs fill factor (assuming that the index method supports it):
211 ALTER INDEX distributors SET (fillfactor = 75);
212 REINDEX INDEX distributors;
218 Set the statistics\-gathering target for an expression index:
224 CREATE INDEX coord_idx ON measured (x, y, (z + t));
225 ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;
237 CREATE INDEX (\fBCREATE_INDEX\fR(7)), \fBREINDEX\fR(7)