Project: YugabyteDB (App Definition and Development / Database)
File: pg-stat-progress-create-index.md

title: View CREATE INDEX status with pgstatprogresscreateindex linkTitle: View CREATE INDEX status description: Use pgstatprogresscreateindex to get the CREATE INDEX command status, including the status of an ongoing concurrent index backfill, and the index build's progress reports. headerTitle: View CREATE INDEX status with pgstatprogresscreateindex menu: v2.18: identifier: pg-stat-progress-create-index parent: query-tuning weight: 450 type: docs You can add a new index to an existing table using the YSQL statement. YugabyteDB supports , which is enabled by default. Using this feature, you can build indexes on non-empty tables online, without failing other concurrent writes. YugabyteDB also supports the statement to disable online index backfill. YugabyteDB supports the PostgreSQL `pgstatprogresscreateindex` view to report the progress of the CREATE INDEX command execution. The view contains one row for each backend connection that is currently running a CREATE INDEX command, and the row entry is cleared after the completion of command execution. The `pgstatprogresscreateindex` view can provide the following details: Number of rows processed during an index backfill. The current phase of the command with `initializing` or `backfilling` as the possible phases. Index progress report for all the different configurations of an index or index build such as non-concurrent index builds, GIN indexes, partial indexes, and include indexes. The following table describes the view columns: | Column | Type | Description | | :-- | : | :- | | pid | integer | Process ID of backend that is running the `CREATE INDEX`. | | datid | OID | Object ID of the database to which this backend is connected. | | datname | name | Name of the database to which this backend is connected. | | relid | OID | Object ID of the indexed relation.| | index_relid | OID | Object ID of the index. | | command | text | The command that is running `CREATE INDEX CONCURRENTLY`, or `CREATE INDEX NONCONCURRENTLY`. | | phase | text | The current phase of the command. The possible phases are initializing, or backfilling. | | tuples_total | bigint | Number of indexed table tuples already processed. | | tuplesdone | bigint | Estimate of total number of tuples (in the indexed table). This value is retrieved from `pgclass.reltuples`. | | partitions_total | bigint | If the ongoing `CREATE INDEX` is for a partitioned table, this refers to the total number of partitions in the table. Set to 0

| | partitions_done | bigint | If the ongoing `CREATE INDEX` is for a partitioned table, this refers to the number of partitions the index has been created for. Set to 0 otherwise. | Columns such as `lockerstotal`, `lockersdone`, `currentlockerpid`, `blockstotal`, and `blocksdone` are not applicable to YugabyteDB and always have null values. The `pgstatprogresscreateindex` view includes the following YugabyteDB-specific changes: In YugabyteDB, the `pgstatprogresscreateindex` view is a local view; it only has entries for CREATE INDEX commands issued by local YSQL clients. In PostgreSQL, `tuplesdone` and `tuplestotal` refer to the tuples of the index. However, in YugabyteDB, these fields refer to the tuples of the indexed table. This discrepancy is only observed for partial indexes, where the reported progress is less than the actual progress. `tuplestotal` is an estimate that is retrieved from `pgclass.reltuples`. In YugabyteDB, `tuplesdone` and `tuplestotal` are not displayed (set to null) for temporary indexes. The following example demonstrates the possible phases (initializing, backfilling) for the CREATE INDEX operation using the `pgstatprogresscreateindex` view. {{% explore-setup-single %}} From your local YugabyteDB installation directory, connect to the shell, and create an index on an existing table as follows: ```sql CREATE TABLE customers(id int, customer_name text); CREATE INDEX ON customers(customer_name); ``` On a separate parallel YSQL connection on the same node, select from the view to see the progress of the command as follows: ```sql SELECT * FROM pgstatprogresscreateindex; ``` ```output pid | datid | datname | relid | indexrelid | command | phase | lockerstotal | lockersdone | currentlockerpid | blockstotal | blocksdone | tuplestotal | tuplesdone | partitionstotal | partitions_done +-+-+-+-++--++--+--+--+-+--+-++-- 78841 | 13291 | yugabyte | 16384 | 16390 | CREATE INDEX CONCURRENTLY | initializing | | | | | | 100000 | 0 | 0 | 0 (1 row) ``` ```sql SELECT * FROM pgstatprogresscreateindex; ``` ```output pid | datid | datname | relid | indexrelid | command | phase | lockerstotal | lockersdone | currentlockerpid | blockstotal | blocksdone | tuplestotal | tuplesdone | partitionstotal | partitions_done +-+-+-+-++-++--+--+--+-+--+-++-- 77444 | 13291 | yugabyte | 16404 | 16412 | CREATE INDEX CONCURRENTLY | backfilling | | | | | | 100000 | 49904 | 0 | 0 (1 row) ``` Refer to to analyze live queries. Refer to to track the COPY operation status. Refer to to optimize YSQL's EXPLAIN and EXPLAIN ANALYZE queries. Refer to show the query execution plan generated by YSQL. Refer to to track planning and execution of all the SQL statements.