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