1ALTER INDEX(7) PostgreSQL 11.3 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:
23
24 RENAME
25 The RENAME form changes the name of the index. If the index is
26 associated with a table constraint (either UNIQUE, PRIMARY KEY, or
27 EXCLUDE), the constraint is renamed as well. There is no effect on
28 the stored data.
29
30 SET TABLESPACE
31 This form changes the index's tablespace to the specified
32 tablespace and moves the data file(s) associated with the index to
33 the new tablespace. To change the tablespace of an index, you must
34 own the index and have CREATE privilege on the new tablespace. All
35 indexes in the current database in a tablespace can be moved by
36 using the ALL IN TABLESPACE form, which will lock all indexes to be
37 moved and then move each one. This form also supports OWNED BY,
38 which will only move indexes owned by the roles specified. If the
39 NOWAIT option is specified then the command will fail if it is
40 unable to acquire all of the locks required immediately. Note that
41 system catalogs will not be moved by this command, use ALTER
42 DATABASE or explicit ALTER INDEX invocations instead if desired.
43 See also CREATE TABLESPACE (CREATE_TABLESPACE(7)).
44
45 ATTACH PARTITION
46 Causes the named index to become attached to the altered index. The
47 named index must be on a partition of the table containing the
48 index being altered, and have an equivalent definition. An attached
49 index cannot be dropped by itself, and will automatically be
50 dropped if its parent index is dropped.
51
52 DEPENDS ON EXTENSION
53 This form marks the index as dependent on the extension, such that
54 if the extension is dropped, the index will automatically be
55 dropped as well.
56
57 SET ( storage_parameter = value [, ... ] )
58 This form changes one or more index-method-specific storage
59 parameters for the index. See CREATE INDEX (CREATE_INDEX(7)) for
60 details on the available parameters. Note that the index contents
61 will not be modified immediately by this command; depending on the
62 parameter you might need to rebuild the index with REINDEX(7) to
63 get the desired effects.
64
65 RESET ( storage_parameter [, ... ] )
66 This form resets one or more index-method-specific storage
67 parameters to their defaults. As with SET, a REINDEX might be
68 needed to update the index entirely.
69
70 ALTER [ COLUMN ] column_number SET STATISTICS integer
71 This form sets the per-column statistics-gathering target for
72 subsequent ANALYZE(7) operations, though can be used only on index
73 columns that are defined as an expression. Since expressions lack a
74 unique name, we refer to them using the ordinal number of the index
75 column. The target can be set in the range 0 to 10000;
76 alternatively, set it to -1 to revert to using the system default
77 statistics target (default_statistics_target). For more information
78 on the use of statistics by the PostgreSQL query planner, refer to
79 Section 14.2.
80
82 IF EXISTS
83 Do not throw an error if the index does not exist. A notice is
84 issued in this case.
85
86 column_number
87 The ordinal number refers to the ordinal (left-to-right) position
88 of the index column.
89
90 name
91 The name (possibly schema-qualified) of an existing index to alter.
92
93 new_name
94 The new name for the index.
95
96 tablespace_name
97 The tablespace to which the index will be moved.
98
99 extension_name
100 The name of the extension that the index is to depend on.
101
102 storage_parameter
103 The name of an index-method-specific storage parameter.
104
105 value
106 The new value for an index-method-specific storage parameter. This
107 might be a number or a word depending on the parameter.
108
110 These operations are also possible using ALTER TABLE (ALTER_TABLE(7)).
111 ALTER INDEX is in fact just an alias for the forms of ALTER TABLE that
112 apply to indexes.
113
114 There was formerly an ALTER INDEX OWNER variant, but this is now
115 ignored (with a warning). An index cannot have an owner different from
116 its table's owner. Changing the table's owner automatically changes the
117 index as well.
118
119 Changing any part of a system catalog index is not permitted.
120
122 To rename an existing index:
123
124 ALTER INDEX distributors RENAME TO suppliers;
125
126 To move an index to a different tablespace:
127
128 ALTER INDEX distributors SET TABLESPACE fasttablespace;
129
130 To change an index's fill factor (assuming that the index method
131 supports it):
132
133 ALTER INDEX distributors SET (fillfactor = 75);
134 REINDEX INDEX distributors;
135
136 Set the statistics-gathering target for an expression index:
137
138 CREATE INDEX coord_idx ON measured (x, y, (z + t));
139 ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;
140
142 ALTER INDEX is a PostgreSQL extension.
143
145 CREATE INDEX (CREATE_INDEX(7)), REINDEX(7)
146
147
148
149PostgreSQL 11.3 2019 ALTER INDEX(7)