{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_INDEX (man)\n\n## NAME\n\nCREATEINDEX - define a new index\n\n## SYNOPSIS\n\nCREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] tablename [ USING method ]\n( { columnname | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclassparameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )\n[ INCLUDE ( columnname [, ...] ) ]\n[ WITH ( storageparameter [= value] [, ... ] ) ]\n[ TABLESPACE tablespacename ]\n[ WHERE predicate ]\n\n## DESCRIPTION\n\nCREATE INDEX constructs an index on the specified column(s) of the specified relation, which\ncan be a table or a materialized view. Indexes are primarily used to enhance database\nperformance (though inappropriate use can result in slower performance).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS** (2 subsections)\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_INDEX",
        "section": "",
        "mode": "man",
        "summary": "CREATEINDEX - define a new index",
        "synopsis": "CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] tablename [ USING method ]\n( { columnname | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclassparameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )\n[ INCLUDE ( columnname [, ...] ) ]\n[ WITH ( storageparameter [= value] [, ... ] ) ]\n[ TABLESPACE tablespacename ]\n[ WHERE predicate ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "To create a unique B-tree index on the column title in the table films:",
            "CREATE UNIQUE INDEX titleidx ON films (title);",
            "To create a unique B-tree index on the column title with included columns director and rating",
            "in the table films:",
            "CREATE UNIQUE INDEX titleidx ON films (title) INCLUDE (director, rating);",
            "To create a B-Tree index with deduplication disabled:",
            "CREATE INDEX titleidx ON films (title) WITH (deduplicateitems = off);",
            "To create an index on the expression lower(title), allowing efficient case-insensitive",
            "searches:",
            "CREATE INDEX ON films ((lower(title)));",
            "(In this example we have chosen to omit the index name, so the system will choose a name,",
            "typically filmsloweridx.)",
            "To create an index with non-default collation:",
            "CREATE INDEX titleidxgerman ON films (title COLLATE \"deDE\");",
            "To create an index with non-default sort ordering of nulls:",
            "CREATE INDEX titleidxnullslow ON films (title NULLS FIRST);",
            "To create an index with non-default fill factor:",
            "CREATE UNIQUE INDEX titleidx ON films (title) WITH (fillfactor = 70);",
            "To create a GIN index with fast updates disabled:",
            "CREATE INDEX ginidx ON documentstable USING GIN (locations) WITH (fastupdate = off);",
            "To create an index on the column code in the table films and have the index reside in the",
            "tablespace indexspace:",
            "CREATE INDEX codeidx ON films (code) TABLESPACE indexspace;",
            "To create a GiST index on a point attribute so that we can efficiently use box operators on",
            "the result of the conversion function:",
            "CREATE INDEX pointloc",
            "ON points USING gist (box(location,location));",
            "SELECT * FROM points",
            "WHERE box(location,location) && '(0,0),(1,1)'::box;",
            "To create an index without locking out writes to the table:",
            "CREATE INDEX CONCURRENTLY salesquantityindex ON salestable (quantity);"
        ],
        "see_also": [
            {
                "name": "ALTERINDEX",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ALTERINDEX/7/json"
            },
            {
                "name": "DROPINDEX",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPINDEX/7/json"
            },
            {
                "name": "REINDEX",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/REINDEX/7/json"
            },
            {
                "name": "INDEX",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/INDEX/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 7,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 35,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 110,
                "subsections": [
                    {
                        "name": "Index Storage Parameters",
                        "lines": 77
                    },
                    {
                        "name": "Building Indexes Concurrently",
                        "lines": 69
                    }
                ]
            },
            {
                "name": "NOTES",
                "lines": 95,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 54,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "CREATEINDEX - define a new index\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON [ ONLY ] tablename [ USING method ]\n( { columnname | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclassparameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )\n[ INCLUDE ( columnname [, ...] ) ]\n[ WITH ( storageparameter [= value] [, ... ] ) ]\n[ TABLESPACE tablespacename ]\n[ WHERE predicate ]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "CREATE INDEX constructs an index on the specified column(s) of the specified relation, which\ncan be a table or a materialized view. Indexes are primarily used to enhance database\nperformance (though inappropriate use can result in slower performance).\n\nThe key field(s) for the index are specified as column names, or alternatively as expressions\nwritten in parentheses. Multiple fields can be specified if the index method supports\nmulticolumn indexes.\n\nAn index field can be an expression computed from the values of one or more columns of the\ntable row. This feature can be used to obtain fast access to data based on some\ntransformation of the basic data. For example, an index computed on upper(col) would allow\nthe clause WHERE upper(col) = 'JIM' to use an index.\n\nPostgreSQL provides the index methods B-tree, hash, GiST, SP-GiST, GIN, and BRIN. Users can\nalso define their own index methods, but that is fairly complicated.\n\nWhen the WHERE clause is present, a partial index is created. A partial index is an index\nthat contains entries for only a portion of a table, usually a portion that is more useful\nfor indexing than the rest of the table. For example, if you have a table that contains both\nbilled and unbilled orders where the unbilled orders take up a small fraction of the total\ntable and yet that is an often used section, you can improve performance by creating an index\non just that portion. Another possible application is to use WHERE with UNIQUE to enforce\nuniqueness over a subset of a table. See Section 11.8 for more discussion.\n\nThe expression used in the WHERE clause can refer only to columns of the underlying table,\nbut it can use all columns, not just the ones being indexed. Presently, subqueries and\naggregate expressions are also forbidden in WHERE. The same restrictions apply to index\nfields that are expressions.\n\nAll functions and operators used in an index definition must be “immutable”, that is, their\nresults must depend only on their arguments and never on any outside influence (such as the\ncontents of another table or the current time). This restriction ensures that the behavior of\nthe index is well-defined. To use a user-defined function in an index expression or WHERE\nclause, remember to mark the function immutable when you create it.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "UNIQUE\nCauses the system to check for duplicate values in the table when the index is created\n(if data already exist) and each time data is added. Attempts to insert or update data\nwhich would result in duplicate entries will generate an error.\n\nAdditional restrictions apply when unique indexes are applied to partitioned tables; see\nCREATE TABLE (CREATETABLE(7)).\n\nCONCURRENTLY\nWhen this option is used, PostgreSQL will build the index without taking any locks that\nprevent concurrent inserts, updates, or deletes on the table; whereas a standard index\nbuild locks out writes (but not reads) on the table until it's done. There are several\ncaveats to be aware of when using this option — see Building Indexes Concurrently below.\n\nFor temporary tables, CREATE INDEX is always non-concurrent, as no other session can\naccess them, and non-concurrent index creation is cheaper.\n\nIF NOT EXISTS\nDo not throw an error if a relation with the same name already exists. A notice is issued\nin this case. Note that there is no guarantee that the existing index is anything like\nthe one that would have been created. Index name is required when IF NOT EXISTS is\nspecified.\n\nINCLUDE\nThe optional INCLUDE clause specifies a list of columns which will be included in the\nindex as non-key columns. A non-key column cannot be used in an index scan search\nqualification, and it is disregarded for purposes of any uniqueness or exclusion\nconstraint enforced by the index. However, an index-only scan can return the contents of\nnon-key columns without having to visit the index's table, since they are available\ndirectly from the index entry. Thus, addition of non-key columns allows index-only scans\nto be used for queries that otherwise could not use them.\n\nIt's wise to be conservative about adding non-key columns to an index, especially wide\ncolumns. If an index tuple exceeds the maximum size allowed for the index type, data\ninsertion will fail. In any case, non-key columns duplicate data from the index's table\nand bloat the size of the index, thus potentially slowing searches. Furthermore, B-tree\ndeduplication is never used with indexes that have a non-key column.\n\nColumns listed in the INCLUDE clause don't need appropriate operator classes; the clause\ncan include columns whose data types don't have operator classes defined for a given\naccess method.\n\nExpressions are not supported as included columns since they cannot be used in index-only\nscans.\n\nCurrently, the B-tree, GiST and SP-GiST index access methods support this feature. In\nthese indexes, the values of columns listed in the INCLUDE clause are included in leaf\ntuples which correspond to heap tuples, but are not included in upper-level index entries\nused for tree navigation.\n\nname\nThe name of the index to be created. No schema name can be included here; the index is\nalways created in the same schema as its parent table. If the name is omitted, PostgreSQL\nchooses a suitable name based on the parent table's name and the indexed column name(s).\n\nONLY\nIndicates not to recurse creating indexes on partitions, if the table is partitioned. The\ndefault is to recurse.\n\ntablename\nThe name (possibly schema-qualified) of the table to be indexed.\n\nmethod\nThe name of the index method to be used. Choices are btree, hash, gist, spgist, gin,\nbrin, or user-installed access methods like bloom. The default method is btree.\n\ncolumnname\nThe name of a column of the table.\n\nexpression\nAn expression based on one or more columns of the table. The expression usually must be\nwritten with surrounding parentheses, as shown in the syntax. However, the parentheses\ncan be omitted if the expression has the form of a function call.\n\ncollation\nThe name of the collation to use for the index. By default, the index uses the collation\ndeclared for the column to be indexed or the result collation of the expression to be\nindexed. Indexes with non-default collations can be useful for queries that involve\nexpressions using non-default collations.\n\nopclass\nThe name of an operator class. See below for details.\n\nopclassparameter\nThe name of an operator class parameter. See below for details.\n\nASC\nSpecifies ascending sort order (which is the default).\n\nDESC\nSpecifies descending sort order.\n\nNULLS FIRST\nSpecifies that nulls sort before non-nulls. This is the default when DESC is specified.\n\nNULLS LAST\nSpecifies that nulls sort after non-nulls. This is the default when DESC is not\nspecified.\n\nstorageparameter\nThe name of an index-method-specific storage parameter. See Index Storage Parameters\nbelow for details.\n\ntablespacename\nThe tablespace in which to create the index. If not specified, defaulttablespace is\nconsulted, or temptablespaces for indexes on temporary tables.\n\npredicate\nThe constraint expression for a partial index.\n",
                "subsections": [
                    {
                        "name": "Index Storage Parameters",
                        "content": "The optional WITH clause specifies storage parameters for the index. Each index method has\nits own set of allowed storage parameters. The B-tree, hash, GiST and SP-GiST index methods\nall accept this parameter:\n\nfillfactor (integer)\nThe fillfactor for an index is a percentage that determines how full the index method\nwill try to pack index pages. For B-trees, leaf pages are filled to this percentage\nduring initial index builds, and also when extending the index at the right (adding new\nlargest key values). If pages subsequently become completely full, they will be split,\nleading to fragmentation of the on-disk index structure. B-trees use a default fillfactor\nof 90, but any integer value from 10 to 100 can be selected.\n\nB-tree indexes on tables where many inserts and/or updates are anticipated can benefit\nfrom lower fillfactor settings at CREATE INDEX time (following bulk loading into the\ntable). Values in the range of 50 - 90 can usefully “smooth out” the rate of page splits\nduring the early life of the B-tree index (lowering fillfactor like this may even lower\nthe absolute number of page splits, though this effect is highly workload dependent). The\nB-tree bottom-up index deletion technique described in Section 64.4.2 is dependent on\nhaving some “extra” space on pages to store “extra” tuple versions, and so can be\naffected by fillfactor (though the effect is usually not significant).\n\nIn other specific cases it might be useful to increase fillfactor to 100 at CREATE INDEX\ntime as a way of maximizing space utilization. You should only consider this when you are\ncompletely sure that the table is static (i.e. that it will never be affected by either\ninserts or updates). A fillfactor setting of 100 otherwise risks harming performance:\neven a few updates or inserts will cause a sudden flood of page splits.\n\nThe other index methods use fillfactor in different but roughly analogous ways; the\ndefault fillfactor varies between methods.\n\nB-tree indexes additionally accept this parameter:\n\ndeduplicateitems (boolean)\nControls usage of the B-tree deduplication technique described in Section 64.4.3. Set to\nON or OFF to enable or disable the optimization. (Alternative spellings of ON and OFF are\nallowed as described in Section 20.1.) The default is ON.\n\nNote\nTurning deduplicateitems off via ALTER INDEX prevents future insertions from\ntriggering deduplication, but does not in itself make existing posting list tuples\nuse the standard tuple representation.\n\nGiST indexes additionally accept this parameter:\n\nbuffering (enum)\nDetermines whether the buffered build technique described in Section 65.4.1 is used to\nbuild the index. With OFF buffering is disabled, with ON it is enabled, and with AUTO it\nis initially disabled, but is turned on on-the-fly once the index size reaches\neffectivecachesize. The default is AUTO. Note that if sorted build is possible, it will\nbe used instead of buffered build unless buffering=ON is specified.\n\nGIN indexes accept different parameters:\n\nfastupdate (boolean)\nThis setting controls usage of the fast update technique described in Section 67.4.1. It\nis a Boolean parameter: ON enables fast update, OFF disables it. The default is ON.\n\nNote\nTurning fastupdate off via ALTER INDEX prevents future insertions from going into the\nlist of pending index entries, but does not in itself flush previous entries. You\nmight want to VACUUM the table or call gincleanpendinglist function afterward to\nensure the pending list is emptied.\n\nginpendinglistlimit (integer)\nCustom ginpendinglistlimit parameter. This value is specified in kilobytes.\n\nBRIN indexes accept different parameters:\n\npagesperrange (integer)\nDefines the number of table blocks that make up one block range for each entry of a BRIN\nindex (see Section 68.1 for more details). The default is 128.\n\nautosummarize (boolean)\nDefines whether a summarization run is queued for the previous page range whenever an\ninsertion is detected on the next one. See Section 68.1.1 for more details. The default\nis off.\n"
                    },
                    {
                        "name": "Building Indexes Concurrently",
                        "content": "Creating an index can interfere with regular operation of a database. Normally PostgreSQL\nlocks the table to be indexed against writes and performs the entire index build with a\nsingle scan of the table. Other transactions can still read the table, but if they try to\ninsert, update, or delete rows in the table they will block until the index build is\nfinished. This could have a severe effect if the system is a live production database. Very\nlarge tables can take many hours to be indexed, and even for smaller tables, an index build\ncan lock out writers for periods that are unacceptably long for a production system.\n\nPostgreSQL supports building indexes without locking out writes. This method is invoked by\nspecifying the CONCURRENTLY option of CREATE INDEX. When this option is used, PostgreSQL must\nperform two scans of the table, and in addition it must wait for all existing transactions\nthat could potentially modify or use the index to terminate. Thus this method requires more\ntotal work than a standard index build and takes significantly longer to complete. However,\nsince it allows normal operations to continue while the index is built, this method is useful\nfor adding new indexes in a production environment. Of course, the extra CPU and I/O load\nimposed by the index creation might slow other operations.\n\nIn a concurrent index build, the index is actually entered as an “invalid” index into the\nsystem catalogs in one transaction, then two table scans occur in two more transactions.\nBefore each table scan, the index build must wait for existing transactions that have\nmodified the table to terminate. After the second scan, the index build must wait for any\ntransactions that have a snapshot (see Chapter 13) predating the second scan to terminate,\nincluding transactions used by any phase of concurrent index builds on other tables, if the\nindexes involved are partial or have columns that are not simple column references. Then\nfinally the index can be marked “valid” and ready for use, and the CREATE INDEX command\nterminates. Even then, however, the index may not be immediately usable for queries: in the\nworst case, it cannot be used as long as transactions exist that predate the start of the\nindex build.\n\nIf a problem arises while scanning the table, such as a deadlock or a uniqueness violation in\na unique index, the CREATE INDEX command will fail but leave behind an “invalid” index. This\nindex will be ignored for querying purposes because it might be incomplete; however it will\nstill consume update overhead. The psql \\d command will report such an index as INVALID:\n\npostgres=# \\d tab\nTable \"public.tab\"\nColumn |  Type   | Collation | Nullable | Default\n--------+---------+-----------+----------+---------\ncol    | integer |           |          |\nIndexes:\n\"idx\" btree (col) INVALID\n\nThe recommended recovery method in such cases is to drop the index and try again to perform\nCREATE INDEX CONCURRENTLY. (Another possibility is to rebuild the index with REINDEX INDEX\nCONCURRENTLY).\n\nAnother caveat when building a unique index concurrently is that the uniqueness constraint is\nalready being enforced against other transactions when the second table scan begins. This\nmeans that constraint violations could be reported in other queries prior to the index\nbecoming available for use, or even in cases where the index build eventually fails. Also, if\na failure does occur in the second scan, the “invalid” index continues to enforce its\nuniqueness constraint afterwards.\n\nConcurrent builds of expression indexes and partial indexes are supported. Errors occurring\nin the evaluation of these expressions could cause behavior similar to that described above\nfor unique constraint violations.\n\nRegular index builds permit other regular index builds on the same table to occur\nsimultaneously, but only one concurrent index build can occur on a table at a time. In either\ncase, schema modification of the table is not allowed while the index is being built. Another\ndifference is that a regular CREATE INDEX command can be performed within a transaction\nblock, but CREATE INDEX CONCURRENTLY cannot.\n\nConcurrent builds for indexes on partitioned tables are currently not supported. However, you\nmay concurrently build the index on each partition individually and then finally create the\npartitioned index non-concurrently in order to reduce the time where writes to the\npartitioned table will be locked out. In this case, building the partitioned index is a\nmetadata only operation.\n"
                    }
                ]
            },
            "NOTES": {
                "content": "See Chapter 11 for information about when indexes can be used, when they are not used, and in\nwhich particular situations they can be useful.\n\nCurrently, only the B-tree, GiST, GIN, and BRIN index methods support multiple-key-column\nindexes. Whether there can be multiple key columns is independent of whether INCLUDE columns\ncan be added to the index. Indexes can have up to 32 columns, including INCLUDE columns.\n(This limit can be altered when building PostgreSQL.) Only B-tree currently supports unique\nindexes.\n\nAn operator class with optional parameters can be specified for each column of an index. The\noperator class identifies the operators to be used by the index for that column. For example,\na B-tree index on four-byte integers would use the int4ops class; this operator class\nincludes comparison functions for four-byte integers. In practice the default operator class\nfor the column's data type is usually sufficient. The main point of having operator classes\nis that for some data types, there could be more than one meaningful ordering. For example,\nwe might want to sort a complex-number data type either by absolute value or by real part. We\ncould do this by defining two operator classes for the data type and then selecting the\nproper class when creating an index. More information about operator classes is in\nSection 11.10 and in Section 38.16.\n\nWhen CREATE INDEX is invoked on a partitioned table, the default behavior is to recurse to\nall partitions to ensure they all have matching indexes. Each partition is first checked to\ndetermine whether an equivalent index already exists, and if so, that index will become\nattached as a partition index to the index being created, which will become its parent index.\nIf no matching index exists, a new index will be created and automatically attached; the name\nof the new index in each partition will be determined as if no index name had been specified\nin the command. If the ONLY option is specified, no recursion is done, and the index is\nmarked invalid. (ALTER INDEX ... ATTACH PARTITION marks the index valid, once all partitions\nacquire matching indexes.) Note, however, that any partition that is created in the future\nusing CREATE TABLE ... PARTITION OF will automatically have a matching index, regardless of\nwhether ONLY is specified.\n\nFor index methods that support ordered scans (currently, only B-tree), the optional clauses\nASC, DESC, NULLS FIRST, and/or NULLS LAST can be specified to modify the sort ordering of the\nindex. Since an ordered index can be scanned either forward or backward, it is not normally\nuseful to create a single-column DESC index — that sort ordering is already available with a\nregular index. The value of these options is that multicolumn indexes can be created that\nmatch the sort ordering requested by a mixed-ordering query, such as SELECT ... ORDER BY x\nASC, y DESC. The NULLS options are useful if you need to support “nulls sort low” behavior,\nrather than the default “nulls sort high”, in queries that depend on indexes to avoid sorting\nsteps.\n\nThe system regularly collects statistics on all of a table's columns. Newly-created\nnon-expression indexes can immediately use these statistics to determine an index's\nusefulness. For new expression indexes, it is necessary to run ANALYZE or wait for the\nautovacuum daemon to analyze the table to generate statistics for these indexes.\n\nFor most index methods, the speed of creating an index is dependent on the setting of\nmaintenanceworkmem. Larger values will reduce the time needed for index creation, so long\nas you don't make it larger than the amount of memory really available, which would drive the\nmachine into swapping.\n\nPostgreSQL can build indexes while leveraging multiple CPUs in order to process the table\nrows faster. This feature is known as parallel index build. For index methods that support\nbuilding indexes in parallel (currently, only B-tree), maintenanceworkmem specifies the\nmaximum amount of memory that can be used by each index build operation as a whole,\nregardless of how many worker processes were started. Generally, a cost model automatically\ndetermines how many worker processes should be requested, if any.\n\nParallel index builds may benefit from increasing maintenanceworkmem where an equivalent\nserial index build will see little or no benefit. Note that maintenanceworkmem may\ninfluence the number of worker processes requested, since parallel workers must have at least\na 32MB share of the total maintenanceworkmem budget. There must also be a remaining 32MB\nshare for the leader process. Increasing maxparallelmaintenanceworkers may allow more\nworkers to be used, which will reduce the time needed for index creation, so long as the\nindex build is not already I/O bound. Of course, there should also be sufficient CPU capacity\nthat would otherwise lie idle.\n\nSetting a value for parallelworkers via ALTER TABLE directly controls how many parallel\nworker processes will be requested by a CREATE INDEX against the table. This bypasses the\ncost model completely, and prevents maintenanceworkmem from affecting how many parallel\nworkers are requested. Setting parallelworkers to 0 via ALTER TABLE will disable parallel\nindex builds on the table in all cases.\n\nTip\nYou might want to reset parallelworkers after setting it as part of tuning an index\nbuild. This avoids inadvertent changes to query plans, since parallelworkers affects all\nparallel table scans.\n\nWhile CREATE INDEX with the CONCURRENTLY option supports parallel builds without special\nrestrictions, only the first table scan is actually performed in parallel.\n\nUse DROP INDEX to remove an index.\n\nLike any long-running transaction, CREATE INDEX on a table can affect which tuples can be\nremoved by concurrent VACUUM on any other table.\n\nPrior releases of PostgreSQL also had an R-tree index method. This method has been removed\nbecause it had no significant advantages over the GiST method. If USING rtree is specified,\nCREATE INDEX will interpret it as USING gist, to simplify conversion of old databases to\nGiST.\n\nEach backend running CREATE INDEX will report its progress in the\npgstatprogresscreateindex view. See Section 28.4.2 for details.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "To create a unique B-tree index on the column title in the table films:\n\nCREATE UNIQUE INDEX titleidx ON films (title);\n\nTo create a unique B-tree index on the column title with included columns director and rating\nin the table films:\n\nCREATE UNIQUE INDEX titleidx ON films (title) INCLUDE (director, rating);\n\nTo create a B-Tree index with deduplication disabled:\n\nCREATE INDEX titleidx ON films (title) WITH (deduplicateitems = off);\n\nTo create an index on the expression lower(title), allowing efficient case-insensitive\nsearches:\n\nCREATE INDEX ON films ((lower(title)));\n\n(In this example we have chosen to omit the index name, so the system will choose a name,\ntypically filmsloweridx.)\n\nTo create an index with non-default collation:\n\nCREATE INDEX titleidxgerman ON films (title COLLATE \"deDE\");\n\nTo create an index with non-default sort ordering of nulls:\n\nCREATE INDEX titleidxnullslow ON films (title NULLS FIRST);\n\nTo create an index with non-default fill factor:\n\nCREATE UNIQUE INDEX titleidx ON films (title) WITH (fillfactor = 70);\n\nTo create a GIN index with fast updates disabled:\n\nCREATE INDEX ginidx ON documentstable USING GIN (locations) WITH (fastupdate = off);\n\nTo create an index on the column code in the table films and have the index reside in the\ntablespace indexspace:\n\nCREATE INDEX codeidx ON films (code) TABLESPACE indexspace;\n\nTo create a GiST index on a point attribute so that we can efficiently use box operators on\nthe result of the conversion function:\n\nCREATE INDEX pointloc\nON points USING gist (box(location,location));\nSELECT * FROM points\nWHERE box(location,location) && '(0,0),(1,1)'::box;\n\nTo create an index without locking out writes to the table:\n\nCREATE INDEX CONCURRENTLY salesquantityindex ON salestable (quantity);\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "CREATE INDEX is a PostgreSQL language extension. There are no provisions for indexes in the\nSQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "ALTER INDEX (ALTERINDEX(7)), DROP INDEX (DROPINDEX(7)), REINDEX(7), Section 28.4.2\n\n\n\nPostgreSQL 14.23                                2026                                 CREATE INDEX(7)",
                "subsections": []
            }
        }
    }
}