Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4c1b4cd

Browse files
Add resource statistics reporting to ANALYZE VERBOSE.
Previously, log_autovacuum_min_duration utilized dedicated code for logging resource statistics, such as system and buffer usage during autoanalyze. However, this logging functionality was not utilized by ANALYZE VERBOSE. This commit adds resource statistics reporting to ANALYZE VERBOSE by reusing the same logging code as autoanalyze. Author: Anthonin Bonnefoy Reviewed-by: Masahiko Sawada Discussion: https://postgr.es/m/CAO6_Xqr__kTTCLkftqS0qSCm-J7_xbRG3Ge2rWhucxQJMJhcRA%40mail.gmail.com
1 parent c584781 commit 4c1b4cd

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/backend/commands/analyze.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
288288
ind;
289289
Relation *Irel;
290290
int nindexes;
291-
bool hasindex;
291+
bool verbose,
292+
instrument,
293+
hasindex;
292294
VacAttrStats **vacattrstats;
293295
AnlIndexData *indexdata;
294296
int targrows,
@@ -308,6 +310,9 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
308310
PgStat_Counter startreadtime = 0;
309311
PgStat_Counter startwritetime = 0;
310312

313+
verbose = (params->options & VACOPT_VERBOSE) != 0;
314+
instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
315+
params->log_min_duration >= 0));
311316
if (inh)
312317
ereport(elevel,
313318
(errmsg("analyzing \"%s.%s\" inheritance tree",
@@ -339,8 +344,11 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
339344
save_nestlevel = NewGUCNestLevel();
340345
RestrictSearchPath();
341346

342-
/* measure elapsed time iff autovacuum logging requires it */
343-
if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
347+
/*
348+
* measure elapsed time if called with verbose or if autovacuum logging
349+
* requires it
350+
*/
351+
if (instrument)
344352
{
345353
if (track_io_timing)
346354
{
@@ -723,17 +731,18 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
723731
vac_close_indexes(nindexes, Irel, NoLock);
724732

725733
/* Log the action if appropriate */
726-
if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
734+
if (instrument)
727735
{
728736
TimestampTz endtime = GetCurrentTimestamp();
729737

730-
if (params->log_min_duration == 0 ||
738+
if (verbose || params->log_min_duration == 0 ||
731739
TimestampDifferenceExceeds(starttime, endtime,
732740
params->log_min_duration))
733741
{
734742
long delay_in_ms;
735743
double read_rate = 0;
736744
double write_rate = 0;
745+
char *msgfmt;
737746
StringInfoData buf;
738747
int64 total_blks_hit;
739748
int64 total_blks_read;
@@ -785,7 +794,13 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
785794
*/
786795

787796
initStringInfo(&buf);
788-
appendStringInfo(&buf, _("automatic analyze of table \"%s.%s.%s\"\n"),
797+
798+
if (AmAutoVacuumWorkerProcess())
799+
msgfmt = _("automatic analyze of table \"%s.%s.%s\"\n");
800+
else
801+
msgfmt = _("finished analyzing table \"%s.%s.%s\"\n");
802+
803+
appendStringInfo(&buf, msgfmt,
789804
get_database_name(MyDatabaseId),
790805
get_namespace_name(RelationGetNamespace(onerel)),
791806
RelationGetRelationName(onerel));
@@ -805,7 +820,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
805820
(long long) total_blks_dirtied);
806821
appendStringInfo(&buf, _("system usage: %s"), pg_rusage_show(&ru0));
807822

808-
ereport(LOG,
823+
ereport(verbose ? INFO : LOG,
809824
(errmsg_internal("%s", buf.data)));
810825

811826
pfree(buf.data);

0 commit comments

Comments
 (0)