Skip to content

Commit 2197b02

Browse files
okbob@github.comhackorum
authored andcommitted
Print opening INFO lines with coulours
By default it use inverse printing for lines: INFO: vacuuming tablename INFO: repacking tablename INFO: analyzing tablename It helps with orientation inside verbose output of REINDEX, VACUUM and ANALYZE commands.
1 parent 6e89028 commit 2197b02

2 files changed

Lines changed: 64 additions & 32 deletions

File tree

src/backend/access/heap/vacuumlazy.c

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
10051005
WalUsage walusage;
10061006
BufferUsage bufferusage;
10071007
StringInfoData buf;
1008+
StringInfoData detail;
10081009
char *msgfmt;
10091010
int32 diff;
10101011
double read_rate = 0,
@@ -1034,7 +1035,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
10341035
* VACUUM VERBOSE ereport
10351036
*/
10361037
Assert(!params->is_wraparound);
1037-
msgfmt = _("finished vacuuming \"%s.%s.%s\": index scans: %d\n");
1038+
msgfmt = _("finished vacuuming \"%s.%s.%s\"");
10381039
}
10391040
else if (params->is_wraparound)
10401041
{
@@ -1045,69 +1046,73 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
10451046
* case all the same, just in case.
10461047
*/
10471048
if (vacrel->aggressive)
1048-
msgfmt = _("automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1049+
msgfmt = _("automatic aggressive vacuum to prevent wraparound of table \"%s.%s.%s\"");
10491050
else
1050-
msgfmt = _("automatic vacuum to prevent wraparound of table \"%s.%s.%s\": index scans: %d\n");
1051+
msgfmt = _("automatic vacuum to prevent wraparound of table \"%s.%s.%s\"");
10511052
}
10521053
else
10531054
{
10541055
if (vacrel->aggressive)
1055-
msgfmt = _("automatic aggressive vacuum of table \"%s.%s.%s\": index scans: %d\n");
1056+
msgfmt = _("automatic aggressive vacuum of table \"%s.%s.%s\"\n");
10561057
else
1057-
msgfmt = _("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n");
1058+
msgfmt = _("automatic vacuum of table \"%s.%s.%s\"");
10581059
}
10591060
appendStringInfo(&buf, msgfmt,
10601061
vacrel->dbname,
10611062
vacrel->relnamespace,
1062-
vacrel->relname,
1063-
vacrel->num_index_scans);
1064-
appendStringInfo(&buf, _("pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
1063+
vacrel->relname);
1064+
1065+
initStringInfo(&detail);
1066+
1067+
appendStringInfo(&detail, "index scans: %d\n", vacrel->num_index_scans);
1068+
1069+
appendStringInfo(&detail, _("pages: %u removed, %u remain, %u scanned (%.2f%% of total), %u eagerly scanned\n"),
10651070
vacrel->removed_pages,
10661071
new_rel_pages,
10671072
vacrel->scanned_pages,
10681073
orig_rel_pages == 0 ? 100.0 :
10691074
100.0 * vacrel->scanned_pages /
10701075
orig_rel_pages,
10711076
vacrel->eager_scanned_pages);
1072-
appendStringInfo(&buf,
1077+
appendStringInfo(&detail,
10731078
_("tuples: %" PRId64 " removed, %" PRId64 " remain, %" PRId64 " are dead but not yet removable\n"),
10741079
vacrel->tuples_deleted,
10751080
(int64) vacrel->new_rel_tuples,
10761081
vacrel->recently_dead_tuples);
10771082
if (vacrel->missed_dead_tuples > 0)
1078-
appendStringInfo(&buf,
1083+
appendStringInfo(&detail,
10791084
_("tuples missed: %" PRId64 " dead from %u pages not removed due to cleanup lock contention\n"),
10801085
vacrel->missed_dead_tuples,
10811086
vacrel->missed_dead_pages);
10821087
diff = (int32) (ReadNextTransactionId() -
10831088
vacrel->cutoffs.OldestXmin);
1084-
appendStringInfo(&buf,
1089+
appendStringInfo(&detail,
10851090
_("removable cutoff: %u, which was %d XIDs old when operation ended\n"),
10861091
vacrel->cutoffs.OldestXmin, diff);
10871092
if (frozenxid_updated)
10881093
{
10891094
diff = (int32) (vacrel->NewRelfrozenXid -
10901095
vacrel->cutoffs.relfrozenxid);
1091-
appendStringInfo(&buf,
1096+
appendStringInfo(&detail,
10921097
_("new relfrozenxid: %u, which is %d XIDs ahead of previous value\n"),
10931098
vacrel->NewRelfrozenXid, diff);
10941099
}
10951100
if (minmulti_updated)
10961101
{
10971102
diff = (int32) (vacrel->NewRelminMxid -
10981103
vacrel->cutoffs.relminmxid);
1099-
appendStringInfo(&buf,
1104+
appendStringInfo(&detail,
11001105
_("new relminmxid: %u, which is %d MXIDs ahead of previous value\n"),
11011106
vacrel->NewRelminMxid, diff);
11021107
}
1103-
appendStringInfo(&buf, _("frozen: %u pages from table (%.2f%% of total) had %" PRId64 " tuples frozen\n"),
1108+
appendStringInfo(&detail, _("frozen: %u pages from table (%.2f%% of total) had %" PRId64 " tuples frozen\n"),
11041109
vacrel->new_frozen_tuple_pages,
11051110
orig_rel_pages == 0 ? 100.0 :
11061111
100.0 * vacrel->new_frozen_tuple_pages /
11071112
orig_rel_pages,
11081113
vacrel->tuples_frozen);
11091114

1110-
appendStringInfo(&buf,
1115+
appendStringInfo(&detail,
11111116
_("visibility map: %u pages set all-visible, %u pages set all-frozen (%u were all-visible)\n"),
11121117
vacrel->new_all_visible_pages,
11131118
vacrel->new_all_visible_all_frozen_pages +
@@ -1116,35 +1121,35 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
11161121
if (vacrel->do_index_vacuuming)
11171122
{
11181123
if (vacrel->nindexes == 0 || vacrel->num_index_scans == 0)
1119-
appendStringInfoString(&buf, _("index scan not needed: "));
1124+
appendStringInfoString(&detail, _("index scan not needed: "));
11201125
else
1121-
appendStringInfoString(&buf, _("index scan needed: "));
1126+
appendStringInfoString(&detail, _("index scan needed: "));
11221127

11231128
msgfmt = _("%u pages from table (%.2f%% of total) had %" PRId64 " dead item identifiers removed\n");
11241129
}
11251130
else
11261131
{
11271132
if (!VacuumFailsafeActive)
1128-
appendStringInfoString(&buf, _("index scan bypassed: "));
1133+
appendStringInfoString(&detail, _("index scan bypassed: "));
11291134
else
1130-
appendStringInfoString(&buf, _("index scan bypassed by failsafe: "));
1135+
appendStringInfoString(&detail, _("index scan bypassed by failsafe: "));
11311136

11321137
msgfmt = _("%u pages from table (%.2f%% of total) have %" PRId64 " dead item identifiers\n");
11331138
}
1134-
appendStringInfo(&buf, msgfmt,
1139+
appendStringInfo(&detail, msgfmt,
11351140
vacrel->lpdead_item_pages,
11361141
orig_rel_pages == 0 ? 100.0 :
11371142
100.0 * vacrel->lpdead_item_pages / orig_rel_pages,
11381143
vacrel->lpdead_items);
11391144

11401145
if (vacrel->worker_usage.vacuum.nplanned > 0)
1141-
appendStringInfo(&buf,
1146+
appendStringInfo(&detail,
11421147
_("parallel workers: index vacuum: %d planned, %d launched in total\n"),
11431148
vacrel->worker_usage.vacuum.nplanned,
11441149
vacrel->worker_usage.vacuum.nlaunched);
11451150

11461151
if (vacrel->worker_usage.cleanup.nplanned > 0)
1147-
appendStringInfo(&buf,
1152+
appendStringInfo(&detail,
11481153
_("parallel workers: index cleanup: %d planned, %d launched\n"),
11491154
vacrel->worker_usage.cleanup.nplanned,
11501155
vacrel->worker_usage.cleanup.nlaunched);
@@ -1156,7 +1161,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
11561161
if (!istat)
11571162
continue;
11581163

1159-
appendStringInfo(&buf,
1164+
appendStringInfo(&detail,
11601165
_("index \"%s\": pages: %u in total, %u newly deleted, %u currently deleted, %u reusable\n"),
11611166
indnames[i],
11621167
istat->num_pages,
@@ -1172,15 +1177,15 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
11721177
* above call to pgstat_progress_end_command() to not clear
11731178
* the st_progress_param array.
11741179
*/
1175-
appendStringInfo(&buf, _("delay time: %.3f ms\n"),
1180+
appendStringInfo(&detail, _("delay time: %.3f ms\n"),
11761181
(double) MyBEEntry->st_progress_param[PROGRESS_VACUUM_DELAY_TIME] / 1000000.0);
11771182
}
11781183
if (track_io_timing)
11791184
{
11801185
double read_ms = (double) (pgStatBlockReadTime - startreadtime) / 1000;
11811186
double write_ms = (double) (pgStatBlockWriteTime - startwritetime) / 1000;
11821187

1183-
appendStringInfo(&buf, _("I/O timings: read: %.3f ms, write: %.3f ms\n"),
1188+
appendStringInfo(&detail, _("I/O timings: read: %.3f ms, write: %.3f ms\n"),
11841189
read_ms, write_ms);
11851190
}
11861191
if (secs_dur > 0 || usecs_dur > 0)
@@ -1190,14 +1195,14 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
11901195
write_rate = (double) BLCKSZ * total_blks_dirtied /
11911196
(1024 * 1024) / (secs_dur + usecs_dur / 1000000.0);
11921197
}
1193-
appendStringInfo(&buf, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
1198+
appendStringInfo(&detail, _("avg read rate: %.3f MB/s, avg write rate: %.3f MB/s\n"),
11941199
read_rate, write_rate);
1195-
appendStringInfo(&buf,
1200+
appendStringInfo(&detail,
11961201
_("buffer usage: %" PRId64 " hits, %" PRId64 " reads, %" PRId64 " dirtied\n"),
11971202
total_blks_hit,
11981203
total_blks_read,
11991204
total_blks_dirtied);
1200-
appendStringInfo(&buf,
1205+
appendStringInfo(&detail,
12011206
_("WAL usage: %" PRId64 " records, %" PRId64 " full page images, %" PRIu64 " bytes, %" PRIu64 " full page image bytes, %" PRId64 " buffers full\n"),
12021207
walusage.wal_records,
12031208
walusage.wal_fpi,
@@ -1213,17 +1218,18 @@ heap_vacuum_rel(Relation rel, const VacuumParams *params,
12131218
* one dead items are collected, even if index vacuuming is
12141219
* disabled.
12151220
*/
1216-
appendStringInfo(&buf,
1221+
appendStringInfo(&detail,
12171222
ngettext("memory usage: dead item storage %.2f MB accumulated across %d reset (limit %.2f MB each)\n",
12181223
"memory usage: dead item storage %.2f MB accumulated across %d resets (limit %.2f MB each)\n",
12191224
vacrel->num_dead_items_resets),
12201225
(double) vacrel->total_dead_items_bytes / (1024 * 1024),
12211226
vacrel->num_dead_items_resets,
12221227
(double) dead_items_max_bytes / (1024 * 1024));
1223-
appendStringInfo(&buf, _("system usage: %s"), pg_rusage_show(&ru0));
1228+
appendStringInfo(&detail, _("system usage: %s"), pg_rusage_show(&ru0));
12241229

12251230
ereport(verbose ? INFO : LOG,
1226-
(errmsg_internal("%s", buf.data)));
1231+
(errmsg_internal("%s", buf.data),
1232+
errdetail_internal("%s", detail.data)));
12271233
pfree(buf.data);
12281234
}
12291235
}

src/common/logging.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ static const char *sgr_error = NULL;
3232
static const char *sgr_warning = NULL;
3333
static const char *sgr_note = NULL;
3434
static const char *sgr_locus = NULL;
35+
static const char *sgr_info = NULL;
3536

3637
#define SGR_ERROR_DEFAULT "01;31"
3738
#define SGR_WARNING_DEFAULT "01;35"
3839
#define SGR_NOTE_DEFAULT "01;36"
3940
#define SGR_LOCUS_DEFAULT "01"
41+
#define SGR_INFO_DEFAULT "07"
4042

4143
#define ANSI_ESCAPE_FMT "\x1b[%sm"
4244
#define ANSI_ESCAPE_RESET "\x1b[0m"
@@ -145,6 +147,8 @@ pg_logging_init(const char *argv0)
145147
sgr_note = strdup(value);
146148
if (strcmp(name, "locus") == 0)
147149
sgr_locus = strdup(value);
150+
if (strcmp(name, "info") == 0)
151+
sgr_info = strdup(value);
148152
}
149153
}
150154

@@ -157,6 +161,7 @@ pg_logging_init(const char *argv0)
157161
sgr_warning = SGR_WARNING_DEFAULT;
158162
sgr_note = SGR_NOTE_DEFAULT;
159163
sgr_locus = SGR_LOCUS_DEFAULT;
164+
sgr_info = SGR_INFO_DEFAULT;
160165
}
161166
}
162167
}
@@ -353,7 +358,28 @@ pg_log_generic_v(enum pg_log_level level, enum pg_log_part part,
353358
if (required_len >= 2 && buf[required_len - 2] == '\n')
354359
buf[required_len - 2] = '\0';
355360

356-
fprintf(stderr, "%s\n", buf);
361+
if (level == PG_LOG_INFO && sgr_info)
362+
{
363+
if (strncmp(buf, "INFO: ", strlen("INFO: ")) == 0)
364+
{
365+
char *firstnl = strchr(buf, '\n');
366+
if (firstnl)
367+
{
368+
*firstnl = '\0';
369+
}
370+
371+
fprintf(stderr, ANSI_ESCAPE_FMT, sgr_info);
372+
fprintf(stderr, "%s\n", buf);
373+
fprintf(stderr, ANSI_ESCAPE_RESET);
374+
375+
if (firstnl)
376+
fprintf(stderr, "%s\n", firstnl + 1);
377+
}
378+
else
379+
fprintf(stderr, "%s\n", buf);
380+
}
381+
else
382+
fprintf(stderr, "%s\n", buf);
357383
if (log_logfile)
358384
{
359385
fprintf(log_logfile, "%s\n", buf);

0 commit comments

Comments
 (0)