mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
Improve logging of autovacuum I/O activity
This adds some I/O stats to the logging of autovacuum (when the operation takes long enough that log_autovacuum_min_duration causes it to be logged), so that it is easier to tune. Notably, it adds buffer I/O counts (hits, misses, dirtied) and read and write rate. Authors: Greg Smith and Noah Misch
This commit is contained in:
@ -214,6 +214,9 @@ vacuum(VacuumStmt *vacstmt, Oid relid, bool do_toast,
|
|||||||
|
|
||||||
VacuumCostActive = (VacuumCostDelay > 0);
|
VacuumCostActive = (VacuumCostDelay > 0);
|
||||||
VacuumCostBalance = 0;
|
VacuumCostBalance = 0;
|
||||||
|
VacuumPageHit = 0;
|
||||||
|
VacuumPageMiss = 0;
|
||||||
|
VacuumPageDirty = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Loop to process each selected relation.
|
* Loop to process each selected relation.
|
||||||
|
@ -155,6 +155,10 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
|
|||||||
BlockNumber possibly_freeable;
|
BlockNumber possibly_freeable;
|
||||||
PGRUsage ru0;
|
PGRUsage ru0;
|
||||||
TimestampTz starttime = 0;
|
TimestampTz starttime = 0;
|
||||||
|
long secs;
|
||||||
|
int usecs;
|
||||||
|
double read_rate,
|
||||||
|
write_rate;
|
||||||
bool scan_all;
|
bool scan_all;
|
||||||
TransactionId freezeTableLimit;
|
TransactionId freezeTableLimit;
|
||||||
BlockNumber new_rel_pages;
|
BlockNumber new_rel_pages;
|
||||||
@ -166,8 +170,7 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
|
|||||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||||
{
|
{
|
||||||
pg_rusage_init(&ru0);
|
pg_rusage_init(&ru0);
|
||||||
if (Log_autovacuum_min_duration > 0)
|
starttime = GetCurrentTimestamp();
|
||||||
starttime = GetCurrentTimestamp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vacstmt->options & VACOPT_VERBOSE)
|
if (vacstmt->options & VACOPT_VERBOSE)
|
||||||
@ -262,13 +265,29 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
|
|||||||
/* and log the action if appropriate */
|
/* and log the action if appropriate */
|
||||||
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
if (IsAutoVacuumWorkerProcess() && Log_autovacuum_min_duration >= 0)
|
||||||
{
|
{
|
||||||
|
TimestampTz endtime = GetCurrentTimestamp();
|
||||||
|
|
||||||
if (Log_autovacuum_min_duration == 0 ||
|
if (Log_autovacuum_min_duration == 0 ||
|
||||||
TimestampDifferenceExceeds(starttime, GetCurrentTimestamp(),
|
TimestampDifferenceExceeds(starttime, endtime,
|
||||||
Log_autovacuum_min_duration))
|
Log_autovacuum_min_duration))
|
||||||
|
{
|
||||||
|
TimestampDifference(starttime, endtime, &secs, &usecs);
|
||||||
|
|
||||||
|
read_rate = 0;
|
||||||
|
write_rate = 0;
|
||||||
|
if ((secs > 0) || (usecs > 0))
|
||||||
|
{
|
||||||
|
read_rate = (double) BLCKSZ * VacuumPageMiss / (1024 * 1024) /
|
||||||
|
(secs + usecs / 1000000.0);
|
||||||
|
write_rate = (double) BLCKSZ * VacuumPageDirty / (1024 * 1024) /
|
||||||
|
(secs + usecs / 1000000.0);
|
||||||
|
}
|
||||||
ereport(LOG,
|
ereport(LOG,
|
||||||
(errmsg("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n"
|
(errmsg("automatic vacuum of table \"%s.%s.%s\": index scans: %d\n"
|
||||||
"pages: %d removed, %d remain\n"
|
"pages: %d removed, %d remain\n"
|
||||||
"tuples: %.0f removed, %.0f remain\n"
|
"tuples: %.0f removed, %.0f remain\n"
|
||||||
|
"buffer usage: %d hits, %d misses, %d dirtied\n"
|
||||||
|
"avg read rate: %.3f MiB/s, avg write rate: %.3f MiB/s\n"
|
||||||
"system usage: %s",
|
"system usage: %s",
|
||||||
get_database_name(MyDatabaseId),
|
get_database_name(MyDatabaseId),
|
||||||
get_namespace_name(RelationGetNamespace(onerel)),
|
get_namespace_name(RelationGetNamespace(onerel)),
|
||||||
@ -277,8 +296,13 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
|
|||||||
vacrelstats->pages_removed,
|
vacrelstats->pages_removed,
|
||||||
vacrelstats->rel_pages,
|
vacrelstats->rel_pages,
|
||||||
vacrelstats->tuples_deleted,
|
vacrelstats->tuples_deleted,
|
||||||
new_rel_tuples,
|
vacrelstats->new_rel_tuples,
|
||||||
|
VacuumPageHit,
|
||||||
|
VacuumPageMiss,
|
||||||
|
VacuumPageDirty,
|
||||||
|
read_rate,write_rate,
|
||||||
pg_rusage_show(&ru0))));
|
pg_rusage_show(&ru0))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +340,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
|
|||||||
{
|
{
|
||||||
/* Just need to update stats before we exit */
|
/* Just need to update stats before we exit */
|
||||||
*hit = true;
|
*hit = true;
|
||||||
|
VacuumPageHit++;
|
||||||
|
|
||||||
if (VacuumCostActive)
|
if (VacuumCostActive)
|
||||||
VacuumCostBalance += VacuumCostPageHit;
|
VacuumCostBalance += VacuumCostPageHit;
|
||||||
@ -471,6 +472,7 @@ ReadBuffer_common(SMgrRelation smgr, char relpersistence, ForkNumber forkNum,
|
|||||||
TerminateBufferIO(bufHdr, false, BM_VALID);
|
TerminateBufferIO(bufHdr, false, BM_VALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VacuumPageMiss++;
|
||||||
if (VacuumCostActive)
|
if (VacuumCostActive)
|
||||||
VacuumCostBalance += VacuumCostPageMiss;
|
VacuumCostBalance += VacuumCostPageMiss;
|
||||||
|
|
||||||
@ -972,10 +974,14 @@ MarkBufferDirty(Buffer buffer)
|
|||||||
Assert(bufHdr->refcount > 0);
|
Assert(bufHdr->refcount > 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the buffer was not dirty already, do vacuum cost accounting.
|
* If the buffer was not dirty already, do vacuum accounting.
|
||||||
*/
|
*/
|
||||||
if (!(bufHdr->flags & BM_DIRTY) && VacuumCostActive)
|
if (!(bufHdr->flags & BM_DIRTY))
|
||||||
VacuumCostBalance += VacuumCostPageDirty;
|
{
|
||||||
|
VacuumPageDirty++;
|
||||||
|
if (VacuumCostActive)
|
||||||
|
VacuumCostBalance += VacuumCostPageDirty;
|
||||||
|
}
|
||||||
|
|
||||||
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
|
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
|
||||||
|
|
||||||
@ -2337,8 +2343,12 @@ SetBufferCommitInfoNeedsSave(Buffer buffer)
|
|||||||
{
|
{
|
||||||
LockBufHdr(bufHdr);
|
LockBufHdr(bufHdr);
|
||||||
Assert(bufHdr->refcount > 0);
|
Assert(bufHdr->refcount > 0);
|
||||||
if (!(bufHdr->flags & BM_DIRTY) && VacuumCostActive)
|
if (!(bufHdr->flags & BM_DIRTY))
|
||||||
VacuumCostBalance += VacuumCostPageDirty;
|
{
|
||||||
|
VacuumPageDirty++;
|
||||||
|
if (VacuumCostActive)
|
||||||
|
VacuumCostBalance += VacuumCostPageDirty;
|
||||||
|
}
|
||||||
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
|
bufHdr->flags |= (BM_DIRTY | BM_JUST_DIRTIED);
|
||||||
UnlockBufHdr(bufHdr);
|
UnlockBufHdr(bufHdr);
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,10 @@ int VacuumCostPageDirty = 20;
|
|||||||
int VacuumCostLimit = 200;
|
int VacuumCostLimit = 200;
|
||||||
int VacuumCostDelay = 0;
|
int VacuumCostDelay = 0;
|
||||||
|
|
||||||
|
int VacuumPageHit = 0;
|
||||||
|
int VacuumPageMiss = 0;
|
||||||
|
int VacuumPageDirty = 0;
|
||||||
|
|
||||||
int VacuumCostBalance = 0; /* working state for vacuum */
|
int VacuumCostBalance = 0; /* working state for vacuum */
|
||||||
bool VacuumCostActive = false;
|
bool VacuumCostActive = false;
|
||||||
|
|
||||||
|
@ -230,6 +230,10 @@ extern int VacuumCostPageDirty;
|
|||||||
extern int VacuumCostLimit;
|
extern int VacuumCostLimit;
|
||||||
extern int VacuumCostDelay;
|
extern int VacuumCostDelay;
|
||||||
|
|
||||||
|
extern int VacuumPageHit;
|
||||||
|
extern int VacuumPageMiss;
|
||||||
|
extern int VacuumPageDirty;
|
||||||
|
|
||||||
extern int VacuumCostBalance;
|
extern int VacuumCostBalance;
|
||||||
extern bool VacuumCostActive;
|
extern bool VacuumCostActive;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user