1ALTER INDEX(7) PostgreSQL 10.7 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 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 ALL IN TABLESPACE name [ OWNED BY role_name [, ... ] ]
15 SET TABLESPACE new_tablespace [ NOWAIT ]
16
18 ALTER INDEX changes the definition of an existing index. There are
19 several subforms:
20
21 RENAME
22 The RENAME form changes the name of the index. There is no effect
23 on the stored data.
24
25 SET TABLESPACE
26 This form changes the index's tablespace to the specified
27 tablespace and moves the data file(s) associated with the index to
28 the new tablespace. To change the tablespace of an index, you must
29 own the index and have CREATE privilege on the new tablespace. All
30 indexes in the current database in a tablespace can be moved by
31 using the ALL IN TABLESPACE form, which will lock all indexes to be
32 moved and then move each one. This form also supports OWNED BY,
33 which will only move indexes owned by the roles specified. If the
34 NOWAIT option is specified then the command will fail if it is
35 unable to acquire all of the locks required immediately. Note that
36 system catalogs will not be moved by this command, use ALTER
37 DATABASE or explicit ALTER INDEX invocations instead if desired.
38 See also CREATE TABLESPACE (CREATE_TABLESPACE(7)).
39
40 DEPENDS ON EXTENSION
41 This form marks the index as dependent on the extension, such that
42 if the extension is dropped, the index will automatically be
43 dropped as well.
44
45 SET ( storage_parameter = value [, ... ] )
46 This form changes one or more index-method-specific storage
47 parameters for the index. See CREATE INDEX (CREATE_INDEX(7)) for
48 details on the available parameters. Note that the index contents
49 will not be modified immediately by this command; depending on the
50 parameter you might need to rebuild the index with REINDEX(7) to
51 get the desired effects.
52
53 RESET ( storage_parameter [, ... ] )
54 This form resets one or more index-method-specific storage
55 parameters to their defaults. As with SET, a REINDEX might be
56 needed to update the index entirely.
57
59 IF EXISTS
60 Do not throw an error if the index does not exist. A notice is
61 issued in this case.
62
63 name
64 The name (possibly schema-qualified) of an existing index to alter.
65
66 new_name
67 The new name for the index.
68
69 tablespace_name
70 The tablespace to which the index will be moved.
71
72 extension_name
73 The name of the extension that the index is to depend on.
74
75 storage_parameter
76 The name of an index-method-specific storage parameter.
77
78 value
79 The new value for an index-method-specific storage parameter. This
80 might be a number or a word depending on the parameter.
81
83 These operations are also possible using ALTER TABLE (ALTER_TABLE(7)).
84 ALTER INDEX is in fact just an alias for the forms of ALTER TABLE that
85 apply to indexes.
86
87 There was formerly an ALTER INDEX OWNER variant, but this is now
88 ignored (with a warning). An index cannot have an owner different from
89 its table's owner. Changing the table's owner automatically changes the
90 index as well.
91
92 Changing any part of a system catalog index is not permitted.
93
95 To rename an existing index:
96
97 ALTER INDEX distributors RENAME TO suppliers;
98
99 To move an index to a different tablespace:
100
101 ALTER INDEX distributors SET TABLESPACE fasttablespace;
102
103 To change an index's fill factor (assuming that the index method
104 supports it):
105
106 ALTER INDEX distributors SET (fillfactor = 75);
107 REINDEX INDEX distributors;
108
110 ALTER INDEX is a PostgreSQL extension.
111
113 CREATE INDEX (CREATE_INDEX(7)), REINDEX(7)
114
115
116
117PostgreSQL 10.7 2019 ALTER INDEX(7)