1ALTER INDEX(7) PostgreSQL 12.6 Documentation ALTER INDEX(7)
2
3
4
6 ALTER_INDEX - change the definition of an index
7
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 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
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 (CREATE_TABLESPACE(7)).
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
58 This form marks the index as dependent on the extension, such that
59 if the extension is dropped, the index will automatically be
60 dropped as well.
61
62 SET ( storage_parameter [= value] [, ... ] )
63 This form changes one or more index-method-specific storage
64 parameters for the index. See CREATE INDEX (CREATE_INDEX(7)) for
65 details on the available parameters. Note that the index contents
66 will not be modified immediately by this command; depending on the
67 parameter you might need to rebuild the index with REINDEX(7) to
68 get the desired effects.
69
70 RESET ( storage_parameter [, ... ] )
71 This form resets one or more index-method-specific storage
72 parameters to their defaults. As with SET, a REINDEX might be
73 needed to update the index entirely.
74
75 ALTER [ COLUMN ] column_number SET STATISTICS integer
76 This form sets the per-column statistics-gathering target for
77 subsequent ANALYZE(7) operations, though can be used only on index
78 columns that are defined as an expression. Since expressions lack a
79 unique name, we refer to them using the ordinal number of the index
80 column. The target can be set in the range 0 to 10000;
81 alternatively, set it to -1 to revert to using the system default
82 statistics target (default_statistics_target). For more information
83 on the use of statistics by the PostgreSQL query planner, refer to
84 Section 14.2.
85
87 IF EXISTS
88 Do not throw an error if the index does not exist. A notice is
89 issued in this case.
90
91 column_number
92 The ordinal number refers to the ordinal (left-to-right) position
93 of the index column.
94
95 name
96 The name (possibly schema-qualified) of an existing index to alter.
97
98 new_name
99 The new name for the index.
100
101 tablespace_name
102 The tablespace to which the index will be moved.
103
104 extension_name
105 The name of the extension that the index is to depend on.
106
107 storage_parameter
108 The name of an index-method-specific storage parameter.
109
110 value
111 The new value for an index-method-specific storage parameter. This
112 might be a number or a word depending on the parameter.
113
115 These operations are also possible using ALTER TABLE (ALTER_TABLE(7)).
116 ALTER INDEX is in fact just an alias for the forms of ALTER TABLE that
117 apply to indexes.
118
119 There was formerly an ALTER INDEX OWNER variant, but this is now
120 ignored (with a warning). An index cannot have an owner different from
121 its table's owner. Changing the table's owner automatically changes the
122 index as well.
123
124 Changing any part of a system catalog index is not permitted.
125
127 To rename an existing index:
128
129 ALTER INDEX distributors RENAME TO suppliers;
130
131 To move an index to a different tablespace:
132
133 ALTER INDEX distributors SET TABLESPACE fasttablespace;
134
135 To change an index's fill factor (assuming that the index method
136 supports it):
137
138 ALTER INDEX distributors SET (fillfactor = 75);
139 REINDEX INDEX distributors;
140
141 Set the statistics-gathering target for an expression index:
142
143 CREATE INDEX coord_idx ON measured (x, y, (z + t));
144 ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;
145
147 ALTER INDEX is a PostgreSQL extension.
148
150 CREATE INDEX (CREATE_INDEX(7)), REINDEX(7)
151
152
153
154PostgreSQL 12.6 2021 ALTER INDEX(7)