]> begriffs open source - ai-pg/blob - full-docs/txt/sql-alterindex.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-alterindex.txt
1
2 ALTER INDEX
3
4    ALTER INDEX — change the definition of an index
5
6 Synopsis
7
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 ]
18
19 Description
20
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,
30           or EXCLUDE), the constraint is renamed as well. There is no
31           effect on 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
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
49           TABLESPACE.
50
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.
58
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.
65
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
72           desired effects.
73
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.
78
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.
89
90 Parameters
91
92    IF EXISTS
93           Do not throw an error if the index does not exist. A notice is
94           issued in this case.
95
96    column_number
97           The ordinal number refers to the ordinal (left-to-right)
98           position of the index column.
99
100    name
101           The name (possibly schema-qualified) of an existing index to
102           alter.
103
104    new_name
105           The new name for the index.
106
107    tablespace_name
108           The tablespace to which the index will be moved.
109
110    extension_name
111           The name of the extension that the index is to depend on.
112
113    storage_parameter
114           The name of an index-method-specific storage parameter.
115
116    value
117           The new value for an index-method-specific storage parameter.
118           This might be a number or a word depending on the parameter.
119
120 Notes
121
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.
124
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
128    index as well.
129
130    Changing any part of a system catalog index is not permitted.
131
132 Examples
133
134    To rename an existing index:
135 ALTER INDEX distributors RENAME TO suppliers;
136
137    To move an index to a different tablespace:
138 ALTER INDEX distributors SET TABLESPACE fasttablespace;
139
140    To change an index's fill factor (assuming that the index method
141    supports it):
142 ALTER INDEX distributors SET (fillfactor = 75);
143 REINDEX INDEX distributors;
144
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;
148
149 Compatibility
150
151    ALTER INDEX is a PostgreSQL extension.
152
153 See Also
154
155    CREATE INDEX, REINDEX