@ -208,19 +208,22 @@ pgstat_drop_relation(Relation rel)
*/
*/
void
void
pgstat_report_vacuum ( Oid tableoid , bool shared ,
pgstat_report_vacuum ( Oid tableoid , bool shared ,
PgStat_Counter livetuples , PgStat_Counter deadtuples )
PgStat_Counter livetuples , PgStat_Counter deadtuples ,
TimestampTz starttime )
{
{
PgStat_EntryRef * entry_ref ;
PgStat_EntryRef * entry_ref ;
PgStatShared_Relation * shtabentry ;
PgStatShared_Relation * shtabentry ;
PgStat_StatTabEntry * tabentry ;
PgStat_StatTabEntry * tabentry ;
Oid dboid = ( shared ? InvalidOid : MyDatabaseId ) ;
Oid dboid = ( shared ? InvalidOid : MyDatabaseId ) ;
TimestampTz ts ;
TimestampTz ts ;
PgStat_Counter elapsedtime ;
if ( ! pgstat_track_counts )
if ( ! pgstat_track_counts )
return ;
return ;
/* Store the data in the table's hash table entry. */
/* Store the data in the table's hash table entry. */
ts = GetCurrentTimestamp ( ) ;
ts = GetCurrentTimestamp ( ) ;
elapsedtime = TimestampDifferenceMilliseconds ( starttime , ts ) ;
/* block acquiring lock for the same reason as pgstat_report_autovac() */
/* block acquiring lock for the same reason as pgstat_report_autovac() */
entry_ref = pgstat_get_entry_ref_locked ( PGSTAT_KIND_RELATION ,
entry_ref = pgstat_get_entry_ref_locked ( PGSTAT_KIND_RELATION ,
@ -248,11 +251,13 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
{
{
tabentry - > last_autovacuum_time = ts ;
tabentry - > last_autovacuum_time = ts ;
tabentry - > autovacuum_count + + ;
tabentry - > autovacuum_count + + ;
tabentry - > total_autovacuum_time + = elapsedtime ;
}
}
else
else
{
{
tabentry - > last_vacuum_time = ts ;
tabentry - > last_vacuum_time = ts ;
tabentry - > vacuum_count + + ;
tabentry - > vacuum_count + + ;
tabentry - > total_vacuum_time + = elapsedtime ;
}
}
pgstat_unlock_entry ( entry_ref ) ;
pgstat_unlock_entry ( entry_ref ) ;
@ -276,12 +281,14 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
void
void
pgstat_report_analyze ( Relation rel ,
pgstat_report_analyze ( Relation rel ,
PgStat_Counter livetuples , PgStat_Counter deadtuples ,
PgStat_Counter livetuples , PgStat_Counter deadtuples ,
bool resetcounter )
bool resetcounter , TimestampTz starttime )
{
{
PgStat_EntryRef * entry_ref ;
PgStat_EntryRef * entry_ref ;
PgStatShared_Relation * shtabentry ;
PgStatShared_Relation * shtabentry ;
PgStat_StatTabEntry * tabentry ;
PgStat_StatTabEntry * tabentry ;
Oid dboid = ( rel - > rd_rel - > relisshared ? InvalidOid : MyDatabaseId ) ;
Oid dboid = ( rel - > rd_rel - > relisshared ? InvalidOid : MyDatabaseId ) ;
TimestampTz ts ;
PgStat_Counter elapsedtime ;
if ( ! pgstat_track_counts )
if ( ! pgstat_track_counts )
return ;
return ;
@ -315,6 +322,10 @@ pgstat_report_analyze(Relation rel,
deadtuples = Max ( deadtuples , 0 ) ;
deadtuples = Max ( deadtuples , 0 ) ;
}
}
/* Store the data in the table's hash table entry. */
ts = GetCurrentTimestamp ( ) ;
elapsedtime = TimestampDifferenceMilliseconds ( starttime , ts ) ;
/* block acquiring lock for the same reason as pgstat_report_autovac() */
/* block acquiring lock for the same reason as pgstat_report_autovac() */
entry_ref = pgstat_get_entry_ref_locked ( PGSTAT_KIND_RELATION , dboid ,
entry_ref = pgstat_get_entry_ref_locked ( PGSTAT_KIND_RELATION , dboid ,
RelationGetRelid ( rel ) ,
RelationGetRelid ( rel ) ,
@ -338,13 +349,15 @@ pgstat_report_analyze(Relation rel,
if ( AmAutoVacuumWorkerProcess ( ) )
if ( AmAutoVacuumWorkerProcess ( ) )
{
{
tabentry - > last_autoanalyze_time = GetCurren tTime stamp ( ) ;
tabentry - > last_autoanalyze_time = ts ;
tabentry - > autoanalyze_count + + ;
tabentry - > autoanalyze_count + + ;
tabentry - > total_autoanalyze_time + = elapsedtime ;
}
}
else
else
{
{
tabentry - > last_analyze_time = GetCurren tTime stamp ( ) ;
tabentry - > last_analyze_time = ts ;
tabentry - > analyze_count + + ;
tabentry - > analyze_count + + ;
tabentry - > total_analyze_time + = elapsedtime ;
}
}
pgstat_unlock_entry ( entry_ref ) ;
pgstat_unlock_entry ( entry_ref ) ;