@@ -336,6 +336,14 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
336336 </entry>
337337 </row>
338338
339+ <row>
340+ <entry><structname>pg_stat_progress_create_index</structname><indexterm><primary>pg_stat_progress_create_index</primary></indexterm></entry>
341+ <entry>One row for each backend running <command>CREATE INDEX</command>, showing
342+ current progress.
343+ See <xref linkend='create-index-progress-reporting'/>.
344+ </entry>
345+ </row>
346+
339347 <row>
340348 <entry><structname>pg_stat_progress_vacuum</structname><indexterm><primary>pg_stat_progress_vacuum</primary></indexterm></entry>
341349 <entry>One row for each backend (including autovacuum worker processes) running
@@ -3403,10 +3411,224 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
34033411 <para>
34043412 <productname>PostgreSQL</productname> has the ability to report the progress of
34053413 certain commands during command execution. Currently, the only commands
3406- which support progress reporting are <command>VACUUM</command> and
3414+ which support progress reporting are <command>CREATE INDEX</command>,
3415+ <command>VACUUM</command> and
34073416 <command>CLUSTER</command>. This may be expanded in the future.
34083417 </para>
34093418
3419+ <sect2 id="create-index-progress-reporting">
3420+ <title>CREATE INDEX Progress Reporting</title>
3421+
3422+ <para>
3423+ Whenever <command>CREATE INDEX</command> is running, the
3424+ <structname>pg_stat_progress_create_index</structname> view will contain
3425+ one row for each backend that is currently creating indexes. The tables
3426+ below describe the information that will be reported and provide information
3427+ about how to interpret it.
3428+ </para>
3429+
3430+ <table id="pg-stat-progress-create-index-view" xreflabel="pg_stat_progress_create_index">
3431+ <title><structname>pg_stat_progress_create_index</structname> View</title>
3432+ <tgroup cols="3">
3433+ <thead>
3434+ <row>
3435+ <entry>Column</entry>
3436+ <entry>Type</entry>
3437+ <entry>Description</entry>
3438+ </row>
3439+ </thead>
3440+
3441+ <tbody>
3442+ <row>
3443+ <entry><structfield>pid</structfield></entry>
3444+ <entry><type>integer</type></entry>
3445+ <entry>Process ID of backend.</entry>
3446+ </row>
3447+ <row>
3448+ <entry><structfield>datid</structfield></entry>
3449+ <entry><type>oid</type></entry>
3450+ <entry>OID of the database to which this backend is connected.</entry>
3451+ </row>
3452+ <row>
3453+ <entry><structfield>datname</structfield></entry>
3454+ <entry><type>name</type></entry>
3455+ <entry>Name of the database to which this backend is connected.</entry>
3456+ </row>
3457+ <row>
3458+ <entry><structfield>relid</structfield></entry>
3459+ <entry><type>oid</type></entry>
3460+ <entry>OID of the table on which the index is being created.</entry>
3461+ </row>
3462+ <row>
3463+ <entry><structfield>phase</structfield></entry>
3464+ <entry><type>text</type></entry>
3465+ <entry>
3466+ Current processing phase of index creation. See <xref linkend='create-index-phases'/>.
3467+ </entry>
3468+ </row>
3469+ <row>
3470+ <entry><structfield>lockers_total</structfield></entry>
3471+ <entry><type>bigint</type></entry>
3472+ <entry>
3473+ Total number of lockers to wait for, when applicable.
3474+ </entry>
3475+ </row>
3476+ <row>
3477+ <entry><structfield>lockers_done</structfield></entry>
3478+ <entry><type>bigint</type></entry>
3479+ <entry>
3480+ Number of lockers already waited for.
3481+ </entry>
3482+ </row>
3483+ <row>
3484+ <entry><structfield>current_locked_pid</structfield></entry>
3485+ <entry><type>bigint</type></entry>
3486+ <entry>
3487+ Process ID of the locker currently being waited for.
3488+ </entry>
3489+ </row>
3490+ <row>
3491+ <entry><structfield>blocks_total</structfield></entry>
3492+ <entry><type>bigint</type></entry>
3493+ <entry>
3494+ Total number of blocks to be processed in the current phase.
3495+ </entry>
3496+ </row>
3497+ <row>
3498+ <entry><structfield>blocks_done</structfield></entry>
3499+ <entry><type>bigint</type></entry>
3500+ <entry>
3501+ Number of blocks already processed in the current phase.
3502+ </entry>
3503+ </row>
3504+ <row>
3505+ <entry><structfield>tuples_total</structfield></entry>
3506+ <entry><type>bigint</type></entry>
3507+ <entry>
3508+ Total number of tuples to be processed in the current phase.
3509+ </entry>
3510+ </row>
3511+ <row>
3512+ <entry><structfield>tuples_done</structfield></entry>
3513+ <entry><type>bigint</type></entry>
3514+ <entry>
3515+ Number of tuples already processed in the current phase.
3516+ </entry>
3517+ </row>
3518+ <row>
3519+ <entry><structfield>partitions_total</structfield></entry>
3520+ <entry><type>bigint</type></entry>
3521+ <entry>
3522+ When creating an index on a partitioned table, this column is set to
3523+ the total number of partitions on which the index is to be created.
3524+ </entry>
3525+ </row>
3526+ <row>
3527+ <entry><structfield>partitions_done</structfield></entry>
3528+ <entry><type>bigint</type></entry>
3529+ <entry>
3530+ When creating an index on a partitioned table, this column is set to
3531+ the number of partitions on which the index has been completed.
3532+ </entry>
3533+ </row>
3534+ </tbody>
3535+ </tgroup>
3536+ </table>
3537+
3538+ <table id="create-index-phases">
3539+ <title>CREATE INDEX phases</title>
3540+ <tgroup cols="2">
3541+ <thead>
3542+ <row>
3543+ <entry>Phase</entry>
3544+ <entry>Description</entry>
3545+ </row>
3546+ </thead>
3547+ <tbody>
3548+ <row>
3549+ <entry><literal>initializing</literal></entry>
3550+ <entry>
3551+ <command>CREATE INDEX</command> is preparing to create the index. This
3552+ phase is expected to be very brief.
3553+ </entry>
3554+ </row>
3555+ <row>
3556+ <entry><literal>waiting for old snapshots</literal></entry>
3557+ <entry>
3558+ <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3559+ that can potentially see the table to release their snapshots.
3560+ This phase is skipped when not in concurrent mode.
3561+ Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3562+ and <structname>current_locker_pid</structname> contain the progress
3563+ information for this phase.
3564+ </entry>
3565+ </row>
3566+ <row>
3567+ <entry><literal>building index</literal></entry>
3568+ <entry>
3569+ The index is being built by the access method-specific code. In this phase,
3570+ access methods that support progress reporting fill in their own progress data,
3571+ and the subphase is indicated in this column. Typically,
3572+ <structname>blocks_total</structname> and <structname>blocks_done</structname>
3573+ will contain progress data, as well as potentially
3574+ <structname>tuples_total</structname> and <structname>tuples_done</structname>.
3575+ </entry>
3576+ </row>
3577+ <row>
3578+ <entry><literal>waiting for writer snapshots</literal></entry>
3579+ <entry>
3580+ <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3581+ that can potentially write into the table to release their snapshots.
3582+ This phase is skipped when not in concurrent mode.
3583+ Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3584+ and <structname>current_locker_pid</structname> contain the progress
3585+ information for this phase.
3586+ </entry>
3587+ </row>
3588+ <row>
3589+ <entry><literal>index validation: scanning index</literal></entry>
3590+ <entry>
3591+ <command>CREATE INDEX CONCURRENTLY</command> is scanning the index searching
3592+ for tuples that need to be validated.
3593+ This phase is skipped when not in concurrent mode.
3594+ Columns <structname>blocks_total</structname> (set to the total size of the index)
3595+ and <structname>blocks_done</structname> contain the progress information for this phase.
3596+ </entry>
3597+ </row>
3598+ <row>
3599+ <entry><literal>index validation: sorting tuples</literal></entry>
3600+ <entry>
3601+ <command>CREATE INDEX CONCURRENTLY</command> is sorting the output of the
3602+ index scanning phase.
3603+ </entry>
3604+ </row>
3605+ <row>
3606+ <entry><literal>index validation: scanning table</literal></entry>
3607+ <entry>
3608+ <command>CREATE INDEX CONCURRENTLY</command> is scanning the table
3609+ to validate the index tuples collected in the previous two phases.
3610+ This phase is skipped when not in concurrent mode.
3611+ Columns <structname>blocks_total</structname> (set to the total size of the table)
3612+ and <structname>blocks_done</structname> contain the progress information for this phase.
3613+ </entry>
3614+ </row>
3615+ <row>
3616+ <entry><literal>waiting for reader snapshots</literal></entry>
3617+ <entry>
3618+ <command>CREATE INDEX CONCURRENTLY</command> is waiting for transactions
3619+ that can potentially see the table to release their snapshots. This
3620+ phase is skipped when not in concurrent mode.
3621+ Columns <structname>lockers_total</structname>, <structname>lockers_done</structname>
3622+ and <structname>current_locker_pid</structname> contain the progress
3623+ information for this phase.
3624+ </entry>
3625+ </row>
3626+ </tbody>
3627+ </tgroup>
3628+ </table>
3629+
3630+ </sect2>
3631+
34103632 <sect2 id="vacuum-progress-reporting">
34113633 <title>VACUUM Progress Reporting</title>
34123634