1ALTER INDEX(7)           PostgreSQL 15.4 Documentation          ALTER INDEX(7)
2
3
4

NAME

6       ALTER_INDEX - change the definition of an index
7

SYNOPSIS

9       ALTER INDEX [ IF EXISTS ] name RENAME TO new_name
10       ALTER INDEX [ IF EXISTS ] name SET TABLESPACE tablespace_name
11       ALTER INDEX name ATTACH PARTITION index_name
12       ALTER INDEX name [ NO ] DEPENDS ON EXTENSION extension_name
13       ALTER INDEX [ IF EXISTS ] name SET ( storage_parameter [= value] [, ... ] )
14       ALTER INDEX [ IF EXISTS ] name RESET ( storage_parameter [, ... ] )
15       ALTER INDEX [ IF EXISTS ] name ALTER [ COLUMN ] column_number
16           SET STATISTICS integer
17       ALTER INDEX ALL IN TABLESPACE name [ OWNED BY role_name [, ... ] ]
18           SET TABLESPACE new_tablespace [ NOWAIT ]
19

DESCRIPTION

21       ALTER INDEX changes the definition of an existing index. There are
22       several subforms described below. Note that the lock level required may
23       differ for each subform. An ACCESS EXCLUSIVE lock is held unless
24       explicitly noted. When multiple subcommands are listed, the lock held
25       will be the strictest one required from any subcommand.
26
27       RENAME
28           The RENAME form changes the name of the index. If the index is
29           associated with a table constraint (either UNIQUE, PRIMARY KEY, or
30           EXCLUDE), the constraint is renamed as well. There is no effect on
31           the stored data.
32
33           Renaming an index acquires a SHARE UPDATE EXCLUSIVE lock.
34
35       SET TABLESPACE
36           This form changes the index's tablespace to the specified
37           tablespace and moves the data file(s) associated with the index to
38           the new tablespace. To change the tablespace of an index, you must
39           own the index and have CREATE privilege on the new tablespace. All
40           indexes in the current database in a tablespace can be moved by
41           using the ALL IN TABLESPACE form, which will lock all indexes to be
42           moved and then move each one. This form also supports OWNED BY,
43           which will only move indexes owned by the roles specified. If the
44           NOWAIT option is specified then the command will fail if it is
45           unable to acquire all of the locks required immediately. Note that
46           system catalogs will not be moved by this command, use ALTER
47           DATABASE or explicit ALTER INDEX invocations instead if desired.
48           See also CREATE TABLESPACE.
49
50       ATTACH PARTITION
51           Causes the named index to become attached to the altered index. The
52           named index must be on a partition of the table containing the
53           index being altered, and have an equivalent definition. An attached
54           index cannot be dropped by itself, and will automatically be
55           dropped if its parent index is dropped.
56
57       DEPENDS ON EXTENSION extension_name
58       NO DEPENDS ON EXTENSION extension_name
59           This form marks the index as dependent on the extension, or no
60           longer dependent on that extension if NO is specified. An index
61           that's marked as dependent on an extension is automatically dropped
62           when the extension is dropped.
63
64       SET ( storage_parameter [= value] [, ... ] )
65           This form changes one or more index-method-specific storage
66           parameters for the index. See CREATE INDEX for details on the
67           available parameters. Note that the index contents will not be
68           modified immediately by this command; depending on the parameter
69           you might need to rebuild the index with REINDEX to get the desired
70           effects.
71
72       RESET ( storage_parameter [, ... ] )
73           This form resets one or more index-method-specific storage
74           parameters to their defaults. As with SET, a REINDEX might be
75           needed to update the index entirely.
76
77       ALTER [ COLUMN ] column_number SET STATISTICS integer
78           This form sets the per-column statistics-gathering target for
79           subsequent ANALYZE operations, though can be used only on index
80           columns that are defined as an expression. Since expressions lack a
81           unique name, we refer to them using the ordinal number of the index
82           column. The target can be set in the range 0 to 10000;
83           alternatively, set it to -1 to revert to using the system default
84           statistics target (default_statistics_target). For more information
85           on the use of statistics by the PostgreSQL query planner, refer to
86           Section 14.2.
87

PARAMETERS

89       IF EXISTS
90           Do not throw an error if the index does not exist. A notice is
91           issued in this case.
92
93       column_number
94           The ordinal number refers to the ordinal (left-to-right) position
95           of the index column.
96
97       name
98           The name (possibly schema-qualified) of an existing index to alter.
99
100       new_name
101           The new name for the index.
102
103       tablespace_name
104           The tablespace to which the index will be moved.
105
106       extension_name
107           The name of the extension that the index is to depend on.
108
109       storage_parameter
110           The name of an index-method-specific storage parameter.
111
112       value
113           The new value for an index-method-specific storage parameter. This
114           might be a number or a word depending on the parameter.
115

NOTES

117       These operations are also possible using ALTER TABLE.  ALTER INDEX is
118       in fact just an alias for the forms of ALTER TABLE that apply to
119       indexes.
120
121       There was formerly an ALTER INDEX OWNER variant, but this is now
122       ignored (with a warning). An index cannot have an owner different from
123       its table's owner. Changing the table's owner automatically changes the
124       index as well.
125
126       Changing any part of a system catalog index is not permitted.
127

EXAMPLES

129       To rename an existing index:
130
131           ALTER INDEX distributors RENAME TO suppliers;
132
133       To move an index to a different tablespace:
134
135           ALTER INDEX distributors SET TABLESPACE fasttablespace;
136
137       To change an index's fill factor (assuming that the index method
138       supports it):
139
140           ALTER INDEX distributors SET (fillfactor = 75);
141           REINDEX INDEX distributors;
142
143       Set the statistics-gathering target for an expression index:
144
145           CREATE INDEX coord_idx ON measured (x, y, (z + t));
146           ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;
147

COMPATIBILITY

149       ALTER INDEX is a PostgreSQL extension.
150

SEE ALSO

152       CREATE INDEX (CREATE_INDEX(7)), REINDEX(7)
153
154
155
156PostgreSQL 15.4                      2023                       ALTER INDEX(7)
Impressum