Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f97457

Browse files
committed
Add progress reporting for CLUSTER and VACUUM FULL.
This uses the same progress reporting infrastructure added in commitc16dc1a and extends it to theseadditional cases. We lack the ability to track the internal progressof sorts and index builds so the information reported iscoarse-grained for some parts of the operation, but it still seemslike a significant improvement over having nothing at all.Tatsuro Yamada, reviewed by Thomas Munro, Masahiko Sawada, MichaelPaquier, Jeff Janes, Alvaro Herrera, Rafia Sabih, and by me. A fairamount of polishing also by me.Discussion:http://postgr.es/m/59A77072.3090401@lab.ntt.co.jp
1 parent1d88a75 commit6f97457

File tree

9 files changed

+373
-8
lines changed

9 files changed

+373
-8
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 193 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,14 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
344344
</entry>
345345
</row>
346346

347+
<row>
348+
<entry><structname>pg_stat_progress_cluster</structname><indexterm><primary>pg_stat_progress_cluster</primary></indexterm></entry>
349+
<entry>One row for each backend running
350+
<command>CLUSTER</command> or <command>VACUUM FULL</command>, showing current progress.
351+
See <xref linkend='cluster-progress-reporting'/>.
352+
</entry>
353+
</row>
354+
347355
</tbody>
348356
</tgroup>
349357
</table>
@@ -3394,9 +3402,9 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
33943402

33953403
<para>
33963404
<productname>PostgreSQL</productname> has the ability to report the progress of
3397-
certain commands during command execution. Currently, the onlycommand
3398-
whichsupports progress reportingis <command>VACUUM</command>. This may be
3399-
expanded in the future.
3405+
certain commands during command execution. Currently, the onlycommands
3406+
whichsupport progress reportingare <command>VACUUM</command> and
3407+
<command>CLUSTER</command>. This may beexpanded in the future.
34003408
</para>
34013409

34023410
<sect2 id="vacuum-progress-reporting">
@@ -3408,9 +3416,11 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
34083416
one row for each backend (including autovacuum worker processes) that is
34093417
currently vacuuming. The tables below describe the information
34103418
that will be reported and provide information about how to interpret it.
3411-
Progress reporting is not currently supported for <command>VACUUM FULL</command>
3412-
and backends running <command>VACUUM FULL</command> will not be listed in this
3413-
view.
3419+
Progress for <command>VACUUM FULL</command> commands is reported via
3420+
<structname>pg_stat_progress_cluster</structname>
3421+
because both <command>VACUUM FULL</command> and <command>CLUSTER</command>
3422+
rewrite the table, while regular <command>VACUUM</command> only modifies it
3423+
in place. See <xref linkend='cluster-progress-reporting'/>.
34143424
</para>
34153425

34163426
<table id="pg-stat-progress-vacuum-view" xreflabel="pg_stat_progress_vacuum">
@@ -3587,6 +3597,183 @@ SELECT pg_stat_get_backend_pid(s.backendid) AS pid,
35873597
</tgroup>
35883598
</table>
35893599

3600+
</sect2>
3601+
3602+
<sect2 id="cluster-progress-reporting">
3603+
<title>CLUSTER Progress Reporting</title>
3604+
3605+
<para>
3606+
Whenever <command>CLUSTER</command> or <command>VACUUM FULL</command> is
3607+
running, the <structname>pg_stat_progress_cluster</structname> view will
3608+
contain a row for each backend that is currently running either command.
3609+
The tables below describe the information that will be reported and
3610+
provide information about how to interpret it.
3611+
</para>
3612+
3613+
<table id="pg-stat-progress-cluster-view" xreflabel="pg_stat_progress_cluster">
3614+
<title><structname>pg_stat_progress_cluster</structname> View</title>
3615+
<tgroup cols="3">
3616+
<thead>
3617+
<row>
3618+
<entry>Column</entry>
3619+
<entry>Type</entry>
3620+
<entry>Description</entry>
3621+
</row>
3622+
</thead>
3623+
3624+
<tbody>
3625+
<row>
3626+
<entry><structfield>pid</structfield></entry>
3627+
<entry><type>integer</type></entry>
3628+
<entry>Process ID of backend.</entry>
3629+
</row>
3630+
<row>
3631+
<entry><structfield>datid</structfield></entry>
3632+
<entry><type>oid</type></entry>
3633+
<entry>OID of the database to which this backend is connected.</entry>
3634+
</row>
3635+
<row>
3636+
<entry><structfield>datname</structfield></entry>
3637+
<entry><type>name</type></entry>
3638+
<entry>Name of the database to which this backend is connected.</entry>
3639+
</row>
3640+
<row>
3641+
<entry><structfield>relid</structfield></entry>
3642+
<entry><type>oid</type></entry>
3643+
<entry>OID of the table being clustered.</entry>
3644+
</row>
3645+
<row>
3646+
<entry><structfield>command</structfield></entry>
3647+
<entry><type>text</type></entry>
3648+
<entry>
3649+
The command that is running. Either CLUSTER or VACUUM FULL.
3650+
</entry>
3651+
</row>
3652+
<row>
3653+
<entry><structfield>phase</structfield></entry>
3654+
<entry><type>text</type></entry>
3655+
<entry>
3656+
Current processing phase. See <xref linkend='cluster-phases' />.
3657+
</entry>
3658+
</row>
3659+
<row>
3660+
<entry><structfield>cluster_index_relid</structfield></entry>
3661+
<entry><type>bigint</type></entry>
3662+
<entry>
3663+
If the table is being scanned using an index, this is the OID of the
3664+
index being used; otherwise, it is zero.
3665+
</entry>
3666+
</row>
3667+
<row>
3668+
<entry><structfield>heap_tuples_scanned</structfield></entry>
3669+
<entry><type>bigint</type></entry>
3670+
<entry>
3671+
Number of heap tuples scanned.
3672+
This counter only advances when the phase is
3673+
<literal>seq scanning heap</literal>,
3674+
<literal>index scanning heap</literal>
3675+
or <literal>writing new heap</literal>.
3676+
</entry>
3677+
</row>
3678+
<row>
3679+
<entry><structfield>heap_tuples_written</structfield></entry>
3680+
<entry><type>bigint</type></entry>
3681+
<entry>
3682+
Number of heap tuples written.
3683+
This counter only advances when the phase is
3684+
<literal>seq scanning heap</literal>,
3685+
<literal>index scanning heap</literal>
3686+
or <literal>writing new heap</literal>.
3687+
</entry>
3688+
</row>
3689+
<row>
3690+
<entry><structfield>heap_blks_total</structfield></entry>
3691+
<entry><type>bigint</type></entry>
3692+
<entry>
3693+
Total number of heap blocks in the table. This number is reported
3694+
as of the beginning of <literal>seq scanning heap</literal>.
3695+
</entry>
3696+
</row>
3697+
<row>
3698+
<entry><structfield>heap_blks_scanned</structfield></entry>
3699+
<entry><type>bigint</type></entry>
3700+
<entry>
3701+
Number of heap blocks scanned. This counter only advances when the
3702+
phase is <literal>seq scanning heap</literal>.
3703+
</entry>
3704+
</row>
3705+
<row>
3706+
<entry><structfield>index_rebuild_count</structfield></entry>
3707+
<entry><type>bigint</type></entry>
3708+
<entry>
3709+
Number of indexes rebuilt. This counter only advances when the phase
3710+
is <literal>rebuilding index</literal>.
3711+
</entry>
3712+
</row>
3713+
</tbody>
3714+
</tgroup>
3715+
</table>
3716+
3717+
<table id="cluster-phases">
3718+
<title>CLUSTER and VACUUM FULL phases</title>
3719+
<tgroup cols="2">
3720+
<thead>
3721+
<row>
3722+
<entry>Phase</entry>
3723+
<entry>Description</entry>
3724+
</row>
3725+
</thead>
3726+
3727+
<tbody>
3728+
<row>
3729+
<entry><literal>initializing</literal></entry>
3730+
<entry>
3731+
The command is preparing to begin scanning the heap. This phase is
3732+
expected to be very brief.
3733+
</entry>
3734+
</row>
3735+
<row>
3736+
<entry><literal>seq scanning heap</literal></entry>
3737+
<entry>
3738+
The command is currently scanning the table using a sequential scan.
3739+
</entry>
3740+
</row>
3741+
<row>
3742+
<entry><literal>index scanning heap</literal></entry>
3743+
<entry>
3744+
<command>CLUSTER</command> is currently scanning the table using an index scan.
3745+
</entry>
3746+
</row>
3747+
<row>
3748+
<entry><literal>sorting tuples</literal></entry>
3749+
<entry>
3750+
<command>CLUSTER</command> is currently sorting tuples.
3751+
</entry>
3752+
</row>
3753+
<row>
3754+
<entry><literal>swapping relation files</literal></entry>
3755+
<entry>
3756+
The command is currently swapping newly-built files into place.
3757+
</entry>
3758+
</row>
3759+
<row>
3760+
<entry><literal>rebuilding index</literal></entry>
3761+
<entry>
3762+
The command is currently rebuilding an index.
3763+
</entry>
3764+
</row>
3765+
<row>
3766+
<entry><literal>performing final cleanup</literal></entry>
3767+
<entry>
3768+
The command is performing final cleanup. When this phase is
3769+
completed, <command>CLUSTER</command>
3770+
or <command>VACUUM FULL</command> will end.
3771+
</entry>
3772+
</row>
3773+
</tbody>
3774+
</tgroup>
3775+
</table>
3776+
35903777
</sect2>
35913778
</sect1>
35923779

‎src/backend/catalog/index.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
#include"catalog/storage.h"
5353
#include"commands/tablecmds.h"
5454
#include"commands/event_trigger.h"
55+
#include"commands/progress.h"
5556
#include"commands/trigger.h"
5657
#include"executor/executor.h"
5758
#include"miscadmin.h"
5859
#include"nodes/makefuncs.h"
5960
#include"nodes/nodeFuncs.h"
6061
#include"optimizer/optimizer.h"
6162
#include"parser/parser.h"
63+
#include"pgstat.h"
6264
#include"rewrite/rewriteManip.h"
6365
#include"storage/bufmgr.h"
6466
#include"storage/lmgr.h"
@@ -3846,6 +3848,7 @@ reindex_relation(Oid relid, int flags, int options)
38463848
List*indexIds;
38473849
boolis_pg_class;
38483850
boolresult;
3851+
inti;
38493852

38503853
/*
38513854
* Open and lock the relation. ShareLock is sufficient since we only need
@@ -3933,6 +3936,7 @@ reindex_relation(Oid relid, int flags, int options)
39333936

39343937
/* Reindex all the indexes. */
39353938
doneIndexes=NIL;
3939+
i=1;
39363940
foreach(indexId,indexIds)
39373941
{
39383942
OidindexOid=lfirst_oid(indexId);
@@ -3950,6 +3954,11 @@ reindex_relation(Oid relid, int flags, int options)
39503954

39513955
if (is_pg_class)
39523956
doneIndexes=lappend_oid(doneIndexes,indexOid);
3957+
3958+
/* Set index rebuild count */
3959+
pgstat_progress_update_param(PROGRESS_CLUSTER_INDEX_REBUILD_COUNT,
3960+
i);
3961+
i++;
39533962
}
39543963
}
39553964
PG_CATCH();

‎src/backend/catalog/system_views.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,33 @@ CREATE VIEW pg_stat_progress_vacuum AS
907907
FROM pg_stat_get_progress_info('VACUUM')AS S
908908
LEFT JOIN pg_database DONS.datid=D.oid;
909909

910+
CREATEVIEWpg_stat_progress_clusterAS
911+
SELECT
912+
S.pidAS pid,
913+
S.datidAS datid,
914+
D.datnameAS datname,
915+
S.relidAS relid,
916+
CASES.param1 WHEN1 THEN'CLUSTER'
917+
WHEN2 THEN'VACUUM FULL'
918+
ENDAS command,
919+
CASES.param2 WHEN0 THEN'initializing'
920+
WHEN1 THEN'seq scanning heap'
921+
WHEN2 THEN'index scanning heap'
922+
WHEN3 THEN'sorting tuples'
923+
WHEN4 THEN'writing new heap'
924+
WHEN5 THEN'swapping relation files'
925+
WHEN6 THEN'rebuilding index'
926+
WHEN7 THEN'performing final cleanup'
927+
ENDAS phase,
928+
S.param3AS cluster_index_relid,
929+
S.param4AS heap_tuples_scanned,
930+
S.param5AS heap_tuples_written,
931+
S.param6AS heap_blks_total,
932+
S.param7AS heap_blks_scanned,
933+
S.param8AS index_rebuild_count
934+
FROM pg_stat_get_progress_info('CLUSTER')AS S
935+
LEFT JOIN pg_database DONS.datid=D.oid;
936+
910937
CREATEVIEWpg_user_mappingsAS
911938
SELECT
912939
U.oidAS umid,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp